Team Ai
Modelpublic

pramodkoujalagi/SmolLM2-360M-Instruct-Text-2-JSON

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes424downloads
Model Card

Developed by: Pramod Koujalagi

SmolLM2-360M-Instruct-Text-2-JSON

A fine-tuned version of SmolLM2-360M-Instruct-bnb-4bit specialized for parsing unstructured calendar event requests into structured JSON data.

Model Description

This model is fine-tuned on SmolLM2-360M-Instruct-bnb-4bit using QLoRA to extract structured calendar event information from natural language text. It identifies and structures key scheduling entities like action, date, time, attendees, location, duration, recurrence, and notes.

๐Ÿ“ฆ Example Usage

You can use the SmolLM2-360M-Instruct-Text-2-JSON model to parse natural language event descriptions into structured JSON format.

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
import json

# Load model and tokenizer
model_name = "pramodkoujalagi/SmolLM2-360M-Instruct-Text-2-JSON"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def parse_calendar_event(text):
    # Format the prompt
    formatted_prompt = f"""<|im_start|>user
Extract the relevant event information from this text and organize it into a JSON structure with fields for action, date, time, attendees, location, duration, recurrence, and notes. If a field is not present, return null for that field.

Text: {text}
<|im_end|>
<|im_start|>assistant
"""

    # Generate response
    inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=512,
            do_sample=True,
            temperature=0.1,
            top_p=0.95,
            pad_token_id=tokenizer.eos_token_id
        )

    # Process response
    output_text = tokenizer.decode(outputs[0], skip_special_tokens=False)
    response = output_text.split("<|im_start|>assistant\n")[1].split("<|im_end|>")[0].strip()

    # Return formatted JSON
    parsed_json = json.loads(response)
    return json.dumps(parsed_json, indent=2)

# Example input
event_text = "Plan an exhibition walkthrough on 15th, April 2028 at 3 PM with Harper, Grace, and Alex in the art gallery for 1 hour, bring bag."

# Output
print("Prompt:")
print(event_text)
print("\nModel Output:")
print(parse_calendar_event(event_text))

Output

Prompt:
Plan an exhibition walkthrough on 15th, April 2028 at 3 PM with Harper, Grace, and Alex in the art gallery for 1 hour, bring bag.

Model Output:
{
  "action": "Plan an exhibition walkthrough",
  "date": "15/04/2028",
  "time": "3:00 PM",
  "attendees": [
    "Harper",
    "Grace",
    "Alex"
  ],
  "location": "art gallery",
  "duration": "1 hour",
  "recurrence": null,
  "notes": "Bring bag"
}

<!--

Example:

Input: "Plan an exhibition walkthrough on 15th, April 2028 at 3 PM with Harper, Grace, and Alex in the art gallery for 1 hour, bring bag."
Output: {
  "action": "Plan an exhibition walkthrough",
  "date": "15/04/2028",
  "time": "3:00 PM",
  "attendees": [
    "Harper",
    "Grace",
    "Alex"
  ],
  "location": "art gallery",
  "duration": "1 hour",
  "recurrence": null,
  "notes": Bring bag
}

Resources for more information:

Use Cases

  • โ€”Calendar application integration
  • โ€”Personal assistant scheduling systems
  • โ€”Meeting summarization tools
  • โ€”Email processing for event extraction

Training Details

Training Data

The model was trained on a custom dataset consisting of 1,149 examples (1,034 training, 115 validation) of natural language event descriptions paired with structured JSON outputs. The dataset includes a wide variety of event types, date/time formats, and varying combinations of fields.

Training Procedure

  • โ€”Fine-tuning method: QLoRA (Quantized Low-Rank Adaptation)
  • โ€”LoRA configuration:
  • โ€”Rank: 64
  • โ€”Alpha: 32
  • โ€”Target modules: All key model components
  • โ€”Rank-stabilized LoRA: Enabled
  • โ€”Training hyperparameters:
  • โ€”Batch size: 8 (2 per device ร— 4 gradient accumulation steps)
  • โ€”Learning rate: 2e-4 with cosine scheduler
  • โ€”Epochs: 3
  • โ€”Weight decay: 0.01
  • โ€”Optimizer: AdamW (8-bit)
  • โ€”Gradient checkpointing: Enabled
  • โ€”Training time: ~15 minutes
  • โ€”Hardware used: T4 GPU

Training Metrics

  • โ€”Final training loss:
  • โ€”Final validation loss:
  • โ€”Validation perplexity: 1.2091