Meaningful sentence generation from words which are classified as per parts of speech

2k Views Asked by At

I am working on Natural Language Generation project. I've created bag of words from paragraph,like nouns,verbs,adjectives.etc and I am trying to generate sentence of pattern Subject+verb+object.
Example:

  • Noun: Elizabeth, Dog, Eiffel Tower, Bike
  • Verb: Sings, barks, shines
  • Current output: Elizabeth shines, Eiffel Tower barks, Bike sings ..etc
  • Expected pairs: Elizabeth sings, Dog barks, Eiffel Tower shines, Bike shines

Subject and verbs must have a relation which will create a meaningful sentence.Is there any way to establish relation between nouns and probable verbs to generate subject+verb pattern?

Also If we have verbs then to find probable objects using input corpus to generate new meaningful sentences?
Example:

  • Verb: riding, reading
  • Objects: horse,bike, books,novels.
  • Expected pairs: riding horse,riding bike, reading books,reading novels.
2

There are 2 best solutions below

0
On

Let's think about it this way. There are certain acts like barking and singing that could only be done by animate beings, thus a bike, an inanimate object, cannot sing. Also, barking is done by an animal, i.e, a human cannot be the one who does the act of barking. So let's define certain features for each one of our constituents. For instance:

eli = {'CAT': 'N', 'ORTH': 'Elizabeth', 'FEAT':'human'}
dog = {'CAT': 'N', 'ORTH': 'dog', 'FEAT':'animal'}
eiffel = {'CAT': 'N', 'ORTH': 'Eiffel Tower', 'FEAT':'inanimate'}
bike = {'CAT': 'N', 'ORTH': 'Bike', 'FEAT':'inanimate'}

nouns = [eli, dog, eiffel, bike]

sings = {'CAT': 'V', 'ORTH': 'sings', 'FEAT':'human'}
barks = {'CAT': 'V', 'ORTH': 'barks', 'FEAT':'animal'}
shines = {'CAT': 'V', 'ORTH': 'shines', 'FEAT':'inanimate'}

verbs = [sings, barks, shines]

# Our sentence pattern is: noun + verb + noun

for n in nouns:
    for v in verbs:
        if n['FEAT'] == v['FEAT']:
            print('{} {}'.format(n['ORTH'], v['ORTH']))

When you run this you get:

>>> 
Elizabeth sings
dog barks
Eiffel Tower shines
Bike shines
>>>

Same goes for pairing verbs with suitable objects. You simply have to assign proper features to your pairs.

0
On

See the set of works under the name of "narrative schemas" by Nate Chambers. He does what you want.

This might be relevant as well.