Views
No views yet
1I am an excelent linquist. The task is to label location entities in the given sentence. Below are some examples
2
3Input: Only France and Britain backed Fischler's proposal.
4Output: Only @@France## and @@Britain## backed Fischler's proposal.
5
6Input: Germany imported 47,000 sheeps from Britain last year, nearly half of total imports.
7Output: @@Germany## imported 47,000 sheeps from @@Britain## last year, nearly half of total imports.
8
9Input: It brought in 4275 tonnes of British mutton, some 10% of overall imports.
10Output: It brought in 4275 tonnes of British mutton, some 10% of overall imports.
11
12Input: China says Taiwan spoils atmosphere for talks.
13Output: @@China## says @@Taiwan## spoils atmosphere for talks.1{
2 "model": "pahautelman/phi2-ner",
3 "train_split": "train",
4 "valid_split": null,
5 "add_eos_token": false,
6 "block_size": 1024,
7 "model_max_length": 1024,
8 "padding": null,
9 "trainer": "sft",
10 "use_flash_attention_2": false,
11 "log": "none",
12 "disable_gradient_checkpointing": false,
13 "logging_steps": -1,
14 "evaluation_strategy": "epoch",
15 "save_total_limit": 1,
16 "save_strategy": "epoch",
17 "auto_find_batch_size": false,
18 "mixed_precision": "fp16",
19 "lr": 0.0002,
20 "epochs": 1,
21 "batch_size": 1,
22 "warmup_ratio": 0.1,
23 "gradient_accumulation": 4,
24 "optimizer": "adamw_torch",
25 "scheduler": "linear",
26 "weight_decay": 0.01,
27 "max_grad_norm": 1.0,
28 "seed": 42,
29 "apply_chat_template": false,
30 "quantization": "int4",
31 "target_modules": null,
32 "merge_adapter": false,
33 "peft": true,
34 "lora_r": 16,
35 "lora_alpha": 32,
36 "lora_dropout": 0.05,
37 "model_ref": null,
38 "dpo_beta": 0.1,
39}1
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path = "pahautelman/phi2-ner-sft-v1"
5
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForCausalLM.from_pretrained(
8 model_path
9).eval()
10
11prompt = 'Label the person entities in the given sentence: Russian President Vladimir Putin is due to arrive in Havana a few hours from now to become the first post-Soviet leader to visit Cuba.'
12
13inputs = tokenizer.encode(prompt, add_special_tokens=False, return_tensors='pt')
14outputs = model.generate(
15 inputs.to(model.device),
16 max_new_tokens=9,
17 do_sample=False,
18)
19output = tokenizer.batch_decode(outputs)[0]
20
21# Model response: "Output: Russian President, Vladimir Putin"
22print(output)