Fine-tuned GPT-3.5 Turbo for Classification: Unexpected Responses Outside Defined Classes

I am currently fine-tuning the “gpt-3.5-turbo-1106” model for event severity classification in four classes - ‘a’, ‘b’, ‘c’, and ‘d’. The training data consists of event details, including name, description, location, associated risk, and severity label.

Here’s how I prepared the training data:

    system_message = "This model is trained to classify the potential severity of events into four categories: { a , b , c , d }. These classes represent increasing levels of severity, with 'a' being the least severe and 'd' being the most severe. Please provide a response that accurately reflects the severity of the event."

    completions = []
    for _, row in df_hazards.iterrows():
        event_name = row['summary']
        event_description = row['detailed_description']
        impact_type = row['potential_severity_type']
        potential_severity = row['categorical_severity']
        exact_place = row['exact_location']
        risk = row['risk_event_title']
        prompt = textwrap.dedent(f"""\
        Event Name: {event_name}
        Event Description: {event_description}
        Exact Place: {exact_place}
        Impact Type: {impact_type}
        Associated Risk: {risk}""")
        # Remove all indentations at the beginning of each line
        prompt = re.sub(r'^\s+', '', prompt, flags=re.MULTILINE)
        completions.append({'messages': [{'role': 'system', 'content': system_message}, {'role': 'user', 'content': prompt}, {'role': 'assistant', 'content': potential_severity}]})

After creating the model using OpenAI’s API, when I validate it with different event scenarios, I notice that the model provides responses outside of the defined classes ‘a’, ‘b’, ‘c’, and ‘d’. I specified in the system message that the model should focus on these classes.

Top logprobs from the model’s responses include unexpected tokens like ‘Event’, ‘Action’, ‘Safety’, etc., which are not part of the defined classes.

I should note that my classes are imbalanced, with counts as follows: ‘a’: 663, ‘b’: 146, ‘c’: 58, ‘d’: 10.

Is there a way to fine-tune the existing model to better align with my defined classes? If not, what recommendations do you have for creating a new model that accurately classifies events into the specified severity classes?

Any assistance or insights would be highly appreciated. Thank you!


do you think the events can be classified at a glance? I.e. do you think that a skilled person could reliably classify these events without thinking or reasoning about them?

I’m also wondering if you wouldn’t rather have some semblance of transparency in your process.

I’m just thinking that you might be better off by asking the model to decomposition the facts, and then come to a conclusion. If you need it in a structured format, you can just instruct the model to wrap everything into a json.

Overall, it might even cost less than finetuning :thinking:

What do you think about that?

The idea of this model is to automate the classification process, which is currently done by one person but takes a long time (there are many events to classify). In addition, I need the answer as a class, because each class corresponds to a level, and I need that level to store in a database.

Could I ask the model for the answer in a certain format where the model makes a conclusion and also gives me the label?

Event 1: Minor Traffic Disruption

  • Event Name: Main Street Marathon
  • Event Description: Annual marathon causing temporary road closures and minor traffic disruption.
  • Exact Place: Main Street from 1st Avenue to 10th Avenue
  • Impact Type: Mobility/Transportation
  • Associated Risk: Low (planned event, well-managed traffic control)
  "discussions": {
    "A": "This event is not catastrophic, does not involve a significant loss of life, extended service outages, or sustained operational disruption. Immediate response is not required since it is a planned event with managed traffic control.",
    "B": "While there might be some disruptions to normal traffic flow, they are neither substantial nor unexpected. This is a planned event which the public is typically made aware of in advance, and thus would not need a rapid response to prevent escalation.",
    "C": "This event fits here as it causes minor disruptions with little to no lasting effect on operations. Response can be scheduled, in this case pre-planned, to manage traffic. Financial loss, if any, would be low and the impact on reputation should be minor given the nature of the event.",
    "D": "The event might also be considered for this category because it is a routine and expected annual occurrence. However, unlike other trivial events, it does cause some disruption, even if minor and well-anticipated."
  "score": "C",
  "notes": "While the event does disrupt normal traffic flow, such disruptions are minor, planned, and well-communicated to the public, fitting the characteristics of a Severity Category C situation. Should there be details emerging that indicate an elevated risk or impact, reevaluation would be necessary."

Event 3: Industrial Accident

  • Event Name: ChemCorp Explosion
  • Event Description: A chemical factory experienced an explosion resulting in a fire, possible toxic fume release, and local evacuations.
  • Exact Place: ChemCorp Plant, Industrial Zone B
  • Impact Type: Chemical/Hazardous Material
  • Associated Risk: High (immediate danger to life and health, potential long-term environmental impacts)
  "discussions": {
    "A": "This event is characterized by a high impact due to the explosion and possible release of toxic fumes, which poses an immediate danger to life and health. The need for local evacuations underscores the urgency of the situation. A chemical plant explosion can lead to a catastrophic situation that involves a significant loss of life, a substantial disruption of operations, and long-term environmental damage. Financial repercussions could be substantial due to the destruction of property, costs of emergency response, and potential legal ramifications. The negative impact on the company's reputation could be significant, as such events often attract a lot of media attention and public scrutiny. Recovery efforts are expected to be long-term and may require external assistance.",
    "B": "While the effects are severe, the categorization as 'Major/Medium Severity' may not entirely capture the catastrophic potential of a chemical plant explosion. However, should the situation be contained rapidly with minimal damage beyond the initial event, it might be downgraded to this severity.",
    "C": "Given the nature of the event, it does not fall under 'Minor/Low Severity'. The immediate danger to life, health, the environment, and the requirement for evacuations are far beyond minor disruptions.",
    "D": "This event definitely does not fall under 'Trivial/Informational'. The implications are too serious and require more than routine activities to manage."
  "score": "A",
  "notes": "The ChemCorp Explosion is a critical incident due to the likely impacts on human life, health, environment, operations, and significant potential financial and reputational losses. Recovery will require extensive resources and time."

What do you think?

Do note that this is a quick and dirty slapjob - you will need to tweak it to your organization’s specifications :cowboy_hat_face:


You are Severity Classifier: The user will post an event, and your job is to analyze it, go through each category, and decide whether it belongs in that category.

These are the classification categories:

Severity Category: A (Critical/High Severity)

  • Impact: Event leads to a catastrophic situation with potential for significant loss of life, extended service outage, or sustained operational disruption.
  • Urgency: Immediate response is required; delay is not acceptable.
  • Financial Loss: Large financial loss, potentially including severe legal or regulatory penalties.
  • Reputation: Substantial negative impact on the organization’s reputation, potentially affecting future operations or viability.
  • Recovery: Long-term recovery efforts; may require external assistance or significant resource reallocation.

Severity Category: B (Major/Medium Severity)

  • Impact: Event causes substantial disruptions that affect normal operations, but it is not catastrophic.
  • Urgency: Response needed within a short period; delay may lead to escalation of the situation.
  • Financial Loss: Moderate financial loss; might include some legal or regulatory penalties.
  • Reputation: Noticeable negative impact on reputation; may attract media attention.
  • Recovery: Medium-term recovery efforts; may involve some operational changes or moderate resource investment.

Severity Category: C (Minor/Low Severity)

  • Impact: Event causes minor disruptions that have little to no lasting effect on operations.
  • Urgency: Response can be scheduled; does not require immediate action unless circumstances change.
  • Financial Loss: Low financial loss; unlikely to result in significant legal or regulatory penalties.
  • Reputation: Minor or no impact on reputation; low public or media interest.
  • Recovery: Short-term recovery efforts; generally resolved within normal operational procedures.

Severity Category: D (Trivial/Informational)

  • Impact: Event has negligible impact on operations or is a normal occurrence that does not require a specific response.
  • Urgency: No response required, or can be dealt with at the convenience of the team.
  • Financial Loss: No financial loss, or loss is within acceptable daily operational variances.
  • Reputation: No impact on the organization’s reputation.
  • Recovery: No recovery efforts needed, or easily managed within routine daily activities.

Please structure your response in the following format:

“discussions”: { // discuss and reflect whether it belongs in the category, for each category
“A”: string,
“B”: string,
“C”: string,
“D”: string,
“score”: “A”|“B”|“C”|“D”|?", // use question mark if you feel you can’t classify it
“notes”?:string // optional, if you have problems categorizing it or the case needs attention from a supervisor

caveat, this was done with 4-1106-p, but you can get similar results with 3.5, just might take a little more effort :slight_smile:

Have you set your max_tokens to 1, and made sure all the training data only has a, b, c, or d?

Yes I had set max_tokens to 1. I added the system message to the completion request and now the model only responds the class “a”. Checking top_logprobs I see that the other options are elements of the classes, however, the token with more probability is always “a”.

You have most of the data in ‘a’. Wonder if this is a training imbalance issue.

If none of this works, try fine tuning ada-002 or davinci-002. That’s what I normally use for classification.

1 Like

The imbalance in the classes is almost certainly a problem.

Can you use your existing data to generate some synthetic data for at least the c and d classes?

I imagine you’d want to aim for at least \sim300 examples per class.

The problem with being so imbalanced is the model might learn it can get pretty good results by simply answering a for everything and do that.

You may consider also including a validation set in your fine-tuning which is evenly distributed even if your actual training data isn’t.

1 Like

If the classes are balanced, would the model infer that each class carries an equal likelihood of occurrence (25% for each in this instance)? However, this doesn’t reflect reality. In the realm of event severities, high severity events do not occur very often. Consequently, the model might fail to capture the authentic distribution of the data.

Maybe you could try training the model on just two classes - is a, is not a.
If not a, run through a second fine-tuned model for b, c, or d.
I’ve had success with a similar approach that uses two fine-tuned models that run in parallel.

1 Like