Spaces:
Runtime error
Runtime error
CesarLeblanc
commited on
Commit
•
f80db47
1
Parent(s):
f4479ea
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from bs4 import BeautifulSoup
|
|
5 |
import random
|
6 |
|
7 |
classification_model = pipeline("text-classification", model="plantbert_text_classification_model", tokenizer="plantbert_text_classification_model")
|
8 |
-
mask_model = pipeline("fill-mask", model="plantbert_fill_mask_model", tokenizer="plantbert_fill_mask_model")
|
9 |
|
10 |
def return_text(habitat_label, habitat_score, confidence):
|
11 |
if habitat_score*100 > confidence:
|
@@ -90,8 +90,14 @@ def masking(text):
|
|
90 |
|
91 |
# Case for the first position
|
92 |
masked_text = "[MASK], " + ', '.join(text.split(', '))
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
score = prediction['score']
|
96 |
sentence = prediction['sequence']
|
97 |
|
@@ -104,8 +110,14 @@ def masking(text):
|
|
104 |
# Loop through each position in the middle of the sentence
|
105 |
for i in range(1, len(text.split(', '))):
|
106 |
masked_text = ', '.join(text.split(', ')[:i]) + ', [MASK], ' + ', '.join(text.split(', ')[i:])
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
score = prediction['score']
|
110 |
sentence = prediction['sequence']
|
111 |
|
@@ -118,8 +130,14 @@ def masking(text):
|
|
118 |
|
119 |
# Case for the last position
|
120 |
masked_text = ', '.join(text.split(', ')) + ', [MASK]'
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
score = prediction['score']
|
124 |
sentence = prediction['sequence']
|
125 |
|
|
|
5 |
import random
|
6 |
|
7 |
classification_model = pipeline("text-classification", model="plantbert_text_classification_model", tokenizer="plantbert_text_classification_model")
|
8 |
+
mask_model = pipeline("fill-mask", model="plantbert_fill_mask_model", tokenizer="plantbert_fill_mask_model", top_k=14189)
|
9 |
|
10 |
def return_text(habitat_label, habitat_score, confidence):
|
11 |
if habitat_score*100 > confidence:
|
|
|
90 |
|
91 |
# Case for the first position
|
92 |
masked_text = "[MASK], " + ', '.join(text.split(', '))
|
93 |
+
i = 0
|
94 |
+
while True:
|
95 |
+
prediction = mask_model(masked_text)[i]
|
96 |
+
species = prediction['token_str']
|
97 |
+
if species in text.split(', '):
|
98 |
+
i+=1
|
99 |
+
else:
|
100 |
+
break
|
101 |
score = prediction['score']
|
102 |
sentence = prediction['sequence']
|
103 |
|
|
|
110 |
# Loop through each position in the middle of the sentence
|
111 |
for i in range(1, len(text.split(', '))):
|
112 |
masked_text = ', '.join(text.split(', ')[:i]) + ', [MASK], ' + ', '.join(text.split(', ')[i:])
|
113 |
+
i = 0
|
114 |
+
while True:
|
115 |
+
prediction = mask_model(masked_text)[i]
|
116 |
+
species = prediction['token_str']
|
117 |
+
if species in text.split(', '):
|
118 |
+
i+=1
|
119 |
+
else:
|
120 |
+
break
|
121 |
score = prediction['score']
|
122 |
sentence = prediction['sequence']
|
123 |
|
|
|
130 |
|
131 |
# Case for the last position
|
132 |
masked_text = ', '.join(text.split(', ')) + ', [MASK]'
|
133 |
+
i = 0
|
134 |
+
while True:
|
135 |
+
prediction = mask_model(masked_text)[i]
|
136 |
+
species = prediction['token_str']
|
137 |
+
if species in text.split(', '):
|
138 |
+
i+=1
|
139 |
+
else:
|
140 |
+
break
|
141 |
score = prediction['score']
|
142 |
sentence = prediction['sequence']
|
143 |
|