pytorch-pcnn icon indicating copy to clipboard operation
pytorch-pcnn copied to clipboard

About lexical feature and sentence feature, there are some question for me?

Open bbruceyuan opened this issue 5 years ago • 1 comments

hi

first of all, thanks for your elegant and easy-understanding code which makes me progress.

But when I read and run your code of this repo, I have two question about the implementation of paper 'relation classification via convoluntional deep neural network, zeng, 2014'.

  • as you know, in the original paper, the author point that lexical feature L5 is much important. but in your code, I didn't find the implementation of getting nouns hypernyms. In my opinion, maybe it's the problem we can not get the paper result, F1 82.7%. Can you fix it lately?
  • additionally, in the original paper, the sentence level word feature, the author use the context feature of each word. for example, sentence {x1, x2, x3} ought to be represented as {[x_s, x1, x2], [x1, x2, x3], [x2, x3, x_e]}. maybe it's an another question? (But I don't think it would impact the result, it may cause the word redundancy)

All in all, it's pretty awesome about your code. Thank you again!

bbruceyuan avatar Apr 11 '19 12:04 bbruceyuan

Last night, I try to add the noun hypeynyms (lexical feature L5) with the following code

from nltk.corpus import wordnet as wn

# add noum hypernyms
noun1 = self.id2word[sen[pos_e1[0]]]
noun2 = self.id2word[sen[pos_e2[0]]]
# print(noun1, noun2)
try:
    noun1_hyper = wn.synsets(noun1)[0].hypernyms()[0].lemma_names()[0]
    noun1_hyper_id = self.word2id.get(noun1_hyper, self.word2id['<PAD>'])
except:
    print('noun1:', noun1)
    noun1_hyper_id = self.word2id['<PAD>']
try:
    noun2_hyper = wn.synsets(noun2)[0].hypernyms()[0].lemma_names()[0]
    noun2_hyper_id = self.word2id.get(noun2_hyper, self.word2id['<PAD>'])
except:
    print('noun2', noun2)
    noun2_hyper_id = self.word2id['<PAD>']

lexical_feature.append([sen[pos_e1[0]], left_e1, right_e1,
                        sen[pos_e2[0]], left_e2, right_e2,
                        noun1_hyper_id, noun2_hyper_id])

why we use try except? because there are some words without hypernyms.

it seems that the L5 feature does not work well just as the author pointing at the paper, though it has little improvement. (which can be ignored from my point of view.)

Did I do anything wrong? and can you give me some advice to leverage the external knowledge?

bbruceyuan avatar Apr 12 '19 01:04 bbruceyuan