X1716/llm-course-hw3-tinyllama-qlora
Model Card for QLoRA-adopted Lite-Oute-1-300M-Instruct
The model was trained with QLoRA adapter to classify the sentiment of twitter messages into 'positive', 'negative', and 'neutral'. It was trained on cardiffnlp/tweeteval dataset. QLoRA-adopted layers include kproj and v_proj weight matrices for all attention layers.
Model Details
The system prompt for the model is as follows:
You are a helpful assistant that classifies the sentiment of a message. Classify the sentiment of the given message as exactly one word: 'negative', 'neutral', or 'positive'. Be brief, respond with exactly one word.
Inputs for the model should be provided in the following format:
Message: "[text of the message]"
The model is trained to output labels in the following format:
Classifying the sentiment of the message as [label].
where [label] is either 'positive', 'negative' or 'neutral'.
Labels can be extracted from the model's outputs with the following function:
~~~python import re def postprocesssentiment(outputtext: str) -> str: """ Extracts the sentiment classification ("positive" or "negative") from the model's output text.
Process:
- Splits the output at the first occurrence of the keyword "assistant" and processes the text after it.
- Uses a regular expression to search for the first occurrence of the words "positive" or "negative" (ignoring case).
- Returns the found sentiment in lowercase. If no match is found, returns an empty string.
Parameters: output_text (str): The complete text output from the model, including conversation headers.
Returns: str: The sentiment classification or empty string """
parts = outputtext.split("assistant", 1) texttoprocess = parts[0] if len(parts) > 1 else outputtext texttoprocess = texttoprocess.lower() match = re.search(rf"\b({'|'.join(IDX2NAME.values())})\b", texttoprocess, re.IGNORECASE) return match.group(1).lower() if match else "" ~~~
Training Details
Only kproj and vproj layers were adopted. Model was trained for 1 epoch with learning rate=5e-4 and batch_size=12. Final loss (CrossEntropy) was 0.8603.
Evaluation
Confusion matrix calculated on the test set is presented below:
It corresponds to macro f1-score of 0.54.
Examples of outputs:
Input (correct label is 'neutral'):
Message: "@user @user That's coming, but I think the victims are going to be Medicaid recipients."
Output:
"Classifying the sentiment of the message as neutral"
Input (correct label is 'negative'):
Message: "@user Wow,first Hugo Chavez and now Fidel Castro. Danny Glover, Michael Moore, Oliver Stone, and Sean Penn are running out of heroes."
Output:
"Classifying the sentiment of the message as negative"
Input (correct label is 'positive'):
Message: "I think I may be finally in with the in crowd #mannequinchallenge #grads2014 @user"
Output:
"Classifying the sentiment of the message as neutral"
