-5

I would like to extract the origin and destination from the given text.

For example,

I am travelling from London to New York.
I am flying to Sydney from Singapore.

Origin -- > London, Singapore. Destination --> Sydney, New York.

NER would give only the Location names, but couldn't fetch the Origin and destination.

Is it possible to train a neural model to detect the same ?

I have tried training the neural networks to classify the text like,

{"tag": "Origin",
     "patterns": ["Flying from ", "Travelling from ", "My source is", ]

This way we could classify the text as origin, but I need to get the values as well (London , Singapore in this case).

Is there anyway we can achieve this?

vignesh
  • 123
  • 11
  • 1
    ["Can Someone Help Me?" is not a valid SO question](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). This usually suggests that what you need is half an hour with a local tutor or walk through a tutorial, rather than Stack Overflow. – Prune May 04 '18 at 23:28
  • 1
    You haven't specified the range of inputs you need to examine, and you show very little effort toward solving the problem. Why do you need a neural model to perform the task? From the examples you've given, the problem is simply a matter of grabbing the place names after the "to" and "from" keywords. – Prune May 04 '18 at 23:30
  • I want to grab the names, even it is given like Source is this location and destination is this location. That is the reason I am trying in neural model. – vignesh May 04 '18 at 23:35
  • If you're trying to get started with neural networks, I'd recommend starting with something numerical. Something like you've presented here has no need for one. – jhpratt May 04 '18 at 23:39
  • I am not actually try to get start with neural networks, just curious to know, if neural network solve this problem. – vignesh May 04 '18 at 23:41
  • Your example output from what you have "trained neural networks to classify text like" doesn't seem like output from a neural network. It looks like you're trying to train a neural network to output a JSON object for some reason? Very confusing. – Nathan May 16 '18 at 14:09

1 Answers1

5

Well, as others commented NN might be an overhead here but they still can be used. To use NN for this problem you can follow the steps:

  1. Collect training data of the form (Text, Origin, Destination), e.g. [("I am travelling from London to New York.", "London", "New York"), ("I am flying to Sydney from Singapore.", "Sydney", "Singapore")]. You may need a lot of data for your NN to be accurate enough.
  2. Vectorise your texts using one of the trained word2vec representations (e.g. glove) into sequences of equal length (say 30, use padding or cutting when necessary) of vectors of equal length. As you are interested in locations, for better training you should vectorize locations into a separate dimension. The resulting array of sequences of vectors will be your input (X) for training.
  3. Your predictions (Y) will also be sequences of length 30 consisting of 0-1 pair vectors, where you put 1 in the first(second) component whenever the corresponding word in your sequence representing text is source(origin) and 0 otherwise.
  4. With this X and Y you can train an LSTM NN (see e.g. keras), set return_sequences = True and specify dimensions correctly.
  5. Then, you can prepare test data in the same way, get the outcome and by the pairs with highest values determine positions of your source and destination in the input text.
Mikhail Berlinkov
  • 1,624
  • 10
  • 15
  • This one is a different perspective , will try this one. But how do vectorise locations into a separate dimension ? – vignesh May 12 '18 at 23:44
  • You can just add to all vectors (which can be represented as lists) one element and set its value to 1 for locations and 0 otherwise. – Mikhail Berlinkov May 13 '18 at 02:41