nontGcob commited on
Commit
c7e97a6
1 Parent(s): 5754359

switch from spacy to stanza for compatibility

Browse files
Files changed (2) hide show
  1. model.py +10 -4
  2. new_requirements.txt +5 -4
model.py CHANGED
@@ -12,14 +12,19 @@ device='cpu'
12
  # Declare the (trained) model that will be used
13
  classifier = transformers.pipeline("zero-shot-classification", model="simple_trained_wsd_pipeline", device=device)
14
 
15
- import spacy
16
  # Part Of Speech tagging (POS tagging)
17
- nlp = spacy.load("en_core_web_sm")
18
 
19
  # Importing as module.
20
  # import en_core_web_sm
21
  # nlp = en_core_web_sm.load()
22
 
 
 
 
 
 
23
  print('successfully download model')
24
 
25
 
@@ -69,8 +74,9 @@ def model(passage, level):
69
  ex1 = nlp(n)
70
 
71
  for word in ex1:
72
- sentence_question_tag = n.replace(word.text, f"[{word.text}]")
73
- text_dict[f"{word.lemma_} = {sentence_question_tag}"] = word.pos_
 
74
 
75
  # Collect the tagging results (filter in just NOUN, PROPN, VERB, ADJ, or ADV only)
76
  collector = {}
 
12
  # Declare the (trained) model that will be used
13
  classifier = transformers.pipeline("zero-shot-classification", model="simple_trained_wsd_pipeline", device=device)
14
 
15
+ # import spacy
16
  # Part Of Speech tagging (POS tagging)
17
+ # nlp = spacy.load("en_core_web_sm")
18
 
19
  # Importing as module.
20
  # import en_core_web_sm
21
  # nlp = en_core_web_sm.load()
22
 
23
+ import stanza
24
+
25
+ # Initialize the English pipeline
26
+ nlp = stanza.Pipeline('en')
27
+
28
  print('successfully download model')
29
 
30
 
 
74
  ex1 = nlp(n)
75
 
76
  for word in ex1:
77
+ sentence_question_tag = n.replace(word.text, f"[{word.text}]") # spacy and stanza use the same entity tag: "word.text"
78
+ # text_dict[f"{word.lemma_} = {sentence_question_tag}"] = word.pos_ # this is for spacy
79
+ text_dict[f"{word.lemma} = {sentence_question_tag}"] = word.upos # this is for stanza
80
 
81
  # Collect the tagging results (filter in just NOUN, PROPN, VERB, ADJ, or ADV only)
82
  collector = {}
new_requirements.txt CHANGED
@@ -147,11 +147,12 @@ smart-open==7.0.4
147
  sniffio==1.3.1
148
  soupsieve==2.6
149
  # spacy==3.7.6
150
- spacy<3.6.0
151
- spacy-legacy==3.0.12
152
- spacy-loggers==1.0.5
153
  srsly==2.4.8
154
  stack-data==0.6.3
 
155
  sympy==1.13.2
156
  terminado==0.18.1
157
  text-unidecode==1.3
@@ -185,4 +186,4 @@ widgetsnbextension==3.6.8
185
  wrapt==1.16.0
186
  xxhash==3.5.0
187
  yarl==1.9.6
188
- https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl
 
147
  sniffio==1.3.1
148
  soupsieve==2.6
149
  # spacy==3.7.6
150
+ # spacy<3.6.0
151
+ # spacy-legacy==3.0.12
152
+ # spacy-loggers==1.0.5
153
  srsly==2.4.8
154
  stack-data==0.6.3
155
+ stanza==1.9.2 # use this instead of spacy
156
  sympy==1.13.2
157
  terminado==0.18.1
158
  text-unidecode==1.3
 
186
  wrapt==1.16.0
187
  xxhash==3.5.0
188
  yarl==1.9.6
189
+ # https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl