Flair_NER/flair_linker.py

31 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
"""Flair_NER_Inference .ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1e-Q1bzMvm1mtRuxwnZBeXRfb-E39hxKu
"""
from flair.data import Sentence
from flair.models import SequenceTagger
from flair.nn import Classifier
input_sentence = """The Constitution of the Islamic Republic of Iran was approved after the victory of the Islamic Revolution on 22 February 1357. Khomeini ordered the Council of Constitutional Experts to compile and promulgate this law. Khamenei sayed yes. In 1385, the budget law of the whole country was approved by the Islamic Council. According to the family and youth law of the population approved on 8/22/1400, the central bank was required to increase the marriage loan. Article (2) of the Direct Taxes Law approved in 1369 does not say anything about the tax on empty houses. According to note (2) of article (5) of the law on provision of basic goods for vulnerable groups, any subsidy increase must be approved by the parliament."""
#tagger: SequenceTagger = SequenceTagger.load("./data/final-model.pt")
tagger = Classifier.load("./data/zelda-v2.pt")
sentence = Sentence(input_sentence)
# load the model
# tagger = Classifier.load('linker')
tagger.predict(sentence)
# iterate over predicted entities and print
for label in sentence.get_labels():
print(label)
for span in sentence.get_spans():
print(span)
c = 0