Spaces:
Runtime error
Runtime error
!pip install --quiet sentencepiece==0.1.95 | |
!pip install --quiet textwrap3==0.9.2 | |
!pip install fastt5==0.1.4 --no-dependencies | |
!pip install numpy | |
!pip install --quiet sentence_transformers | |
# Named entities extraction by DeepPavlov and CAILA | |
import requests | |
import re | |
import json | |
import numpy as np | |
def ner_deeppavlov(text): | |
url = "https://app.caila.io/api/cailagate/account/1632178/model/513/predict" | |
payload = {'texts': [text]} | |
response = requests.post(url, data=json.dumps(payload), headers={"Content-Type": "application/json", "CAILA-API-KEY": "1000044412.2029.CUH5g7Egkk5h4h5IEDeB2SAAOnhM9Xu6Jiks7YtA"}) | |
data = response.json() | |
print(data['entities_list'][0]['entities']) | |
dict = data['entities_list'][0]['entities'] | |
ner = [] | |
for key in dict: | |
ner.append(key['value']) | |
print(key['value']) | |
ner = np.unique(ner, axis=0) | |
ner1 = [] | |
for kw in ner: | |
distractors = russian_distributional_thesaurus(kw) | |
print("keyword ="+kw) | |
if len(distractors)>0: | |
print(distractors) | |
ner1.append([kw] + distractors) | |
else: | |
print("пусто") | |
return ner1 | |
text = """Только за октябрь противник потерял свыше 12 тысяч военнослужащих, 18 самолетов, 12 вертолетов, шесть зенитно-ракетных комплексов, более 200 танков, более 800 других боевых броневых машин, 21 боевую машину реактивных систем залпового огня, уничтожено порядка 350 наемников.""" | |
ner_deeppavlov(text) | |