Hi all,
I have a small annotated data set and i want to do Multi class text classification with GPT4. Please route me towards any guide or give me a over all direction so i can do it.
I have searched this forum but couldnot find a relevancy towards Multi class.
I also have tried Curie to build a model with my data set but i thing some thing is missing so my accuracy was 0 percent.
here is the code:
import openai
Initialize the OpenAI API with your key
openai.api_key = “API key”
Define the fine-tuned model ID
fine_tuned_model_id = “curie:ft-my model”
Take input for unseen data
unseen_data = input("Enter the unseen data: ")
Classify using the fine-tuned model
response = openai.Completion.create(
model=fine_tuned_model_id,
prompt=unseen_data + “\n\n###\n\n”,
max_tokens=1
)
Print the classification result
print(“Classification Result:”, response.choices[0].text.strip())
Evaluation using a predefined validation dataset
validation_data = [
{“input”: “I’ve struggled for a long while. Second grade I had anger and drug issues that made me an outsider. It just got worse from there. Now I’m 20.”, “expected_output”: “Drug and Alcohol”},
{“input”: “i remember being a small child left alone in a giant house and feeling insane fear of monsters, ghosts and zombies with no one to comfort me. i would cry and scream yet no one still would come for me.”, “expected_output”: “Early Life”},
# … add more validation data as needed
]
correct_predictions = 0
for data in validation_data:
response = openai.Completion.create(
model=fine_tuned_model_id,
prompt=data[“input”] + “\n\n###\n\n”,
max_tokens=1
)
predicted_output = response.choices[0].text.strip()
if predicted_output == data[“expected_output”]:
correct_predictions += 1
accuracy = correct_predictions / len(validation_data) * 100
print(f"Model Accuracy: {accuracy:.2f}%")