Views
No views yet
meta-llama/Llama-3.2-1B optimized for Persona Classifier tasks when given a Detailed Persona. The training was done on argilla/FinePersonas-v0.1 dataset with the 10k records.meta-llama/Llama-3.2-1B1from transformers import pipeline
2
3
4model_id_new = "Vedant3907/Llama-3.2-1B-PersonaClassifier"
5
6tokenzier = AutoTokenizer.from_pretrained(model_id_new)
7model_pretrained = AutoModelForCausalLM.from_pretrained(
8 model_id_new,
9 device_map="auto",
10 torch_dtype="float16")
11
12prompt = """Given the persona give the associated labels:
13### Persona:
14 A social justice activist and blogger focused on anti-colonialism, anti-racism, and media representation, particularly within the context of intersectional people of color experiences.
15
16### Labels:
17"""
18
19pipe = pipeline(task="text-generation",
20 model=model_pretrained,
21 tokenizer=tokenizer,
22 max_new_tokens=50,
23 temperature=0.1,
24 pad_token_id = tokenizer.eos_token_id)
25
26result = pipe(prompt)
27
28print(extract_labels(result[0]['generated_text']))
29
30
31#The extract_labels function is to print just the lsit of persona generated by model if sometime it generates random things.
32
33'''
34import re
35
36def extract_labels(output_text):
37 """
38 Extracts the list of labels from the generated text.
39 Args:
40 output_text (str): The raw output text from the model.
41 Returns:
42 list: A list of labels if found, otherwise an empty list.
43 """
44 try:
45 # Find the content after "Labels:" and extract the list
46 match = re.search(r"### Labels:\s*(\[.*?\])", output_text)
47 if match:
48 labels = eval(match.group(1)) # Convert string representation of list to Python list
49 if isinstance(labels, list):
50 return labels
51 except Exception as e:
52 print(f"Error extracting labels: {e}")
53
54 # Return an empty list if extraction fails
55 return []
56'''1training_arguments = TrainingArguments(
2 output_dir=output_dir,
3 num_train_epochs=3,
4 per_device_train_batch_size=1,
5 gradient_accumulation_steps=8,
6 optim="paged_adamw_32bit",
7 logging_steps=10,
8 learning_rate=2e-4,
9 fp16=True,
10 bf16=False,
11 max_grad_norm=0.3,
12 # max_steps=-1,
13 warmup_steps=7,
14 group_by_length=False,
15 lr_scheduler_type="cosine",
16 report_to="wandb",
17 eval_strategy="steps",
18 eval_steps = 0.2
19)