yzhangcs / parser

:rocket: State-of-the-art parsers for natural language.
https://parser.yzhang.site/
MIT License
827 stars 139 forks source link

Cannot use RoBerta CRF model for constituency parsing #71

Closed emadg closed 3 years ago

emadg commented 3 years ago

Hi,

I tried your demo on your GitHub to create a constituency parser with the RoBerta CRF pre-trained model but get an error when running parsing.

con = Parser.load('crf-con-roberta-en')

sent = "This is my sentence to be parsed with SuPar !"

parse = con.predict(sent.split(), verbose=False)

print(parse[0])

got this error:

AttributeError                            Traceback (most recent call last)
<ipython-input-16-7b8ab5d2fd23> in <module>()
      1 sent = "This is my sentence to be parsed with SuPar !"
----> 2 parse = con.predict(sent.split(), verbose=False)
      3 print(parse[0])

5 frames
/usr/local/lib/python3.7/dist-packages/supar/utils/transform.py in build(cls, tree, sequence)
    687         """
    688 
--> 689         root = tree.label()
    690         leaves = [subtree for subtree in tree.subtrees()
    691                   if not isinstance(subtree[0], nltk.Tree)]

AttributeError: 'Tensor' object has no attribute 'label'

Here is a Google colab to try and reproduce the problem: (check Issue # 2) https://colab.research.google.com/drive/1CDZRPab8P4ba7amPxy5jhY6mBrdJ54B4?usp=sharing

yzhangcs commented 3 years ago

@emadg Thank you for pointing this out. Please download the new release and check it again.