Views
No views yet
1git clone https://github.com/ovbystrova/InstructionNER
2cd InstructionNER1from instruction_ner.model import Model
2
3model = Model(
4 model_path_or_name="olgaduchovny/t5-base-ner-mit-restaurant",
5 tokenizer_path_or_name="olgaduchovny/t5-base-mit-restaurant"
6)
7
8options = ["LOC", "PER", "ORG", "MISC"]
9
10instruction = "please extract entities and their types from the input sentence, " \
11 "all entity types are in options"
12
13text = "Once I visited Sovok in Nizny Novgorod. I had asian wok there. It was the best WOK i ever had"\
14 "It was cheap but lemonades cost 5 dollars."
15
16generation_kwargs = {
17 "num_beams": 2,
18 "max_length": 128
19}
20
21pred_spans = model.predict(
22 text=text,
23 generation_kwargs=generation_kwargs,
24 instruction=instruction,
25 options=options
26)
27
28>>> ('sovok is a Restaurant_Name, Nizny Novgorod is a Location, asian wok is a Dish, cheap is a Price, lemonades is a Dish, 5 dollars is a Price.',
29 [(24, 38, 'Location'),
30 (46, 55, 'Dish'),
31 (100, 105, 'Price'),
32 (110, 119, 'Dish'),
33 (125, 134, 'Price')])