Views
No views yet
SmolLM-360M fine-tuned for calendar event entity extraction.
Extracts structured information from natural language event descriptions.1from transformers import AutoTokenizer, AutoModelForCausalLM
2import json
3
4# Load model and tokenizer
5model_name = "smollm-360m-event-extraction"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(model_name)
8
9# Example event text
10event_text = "Team meeting tomorrow at 2pm with John and Sarah for 1 hour"
11
12# Create prompt
13prompt = f'''Extract the following entities from the calendar event description:
14
15Event: {event_text}
16
17Please provide the extracted information in this exact JSON format:
18{{
19 "action": "extracted action or null",
20 "date": "extracted date or null",
21 "time": "extracted time or null",
22 "attendees": ["list of attendees"] or null,
23 "location": "extracted location or null",
24 "duration": "extracted duration or null",
25 "recurrence": "extracted recurrence or null",
26 "notes": "extracted notes or null"
27}}
28
29Extracted entities:'''
30
31# Tokenize and generate
32inputs = tokenizer(prompt, return_tensors="pt")
33outputs = model.generate(**inputs, max_new_tokens=200, temperature=0.1)
34response = tokenizer.decode(outputs[0], skip_special_tokens=True)
35
36# Extract and parse JSON
37generated_json = response[len(prompt):].strip()
38entities = json.loads(generated_json)
39print(entities)1def extract_entities_batch(event_texts, model, tokenizer):
2 results = []
3 for event_text in event_texts:
4 # Use the same prompt format as above
5 # ... (generation code)
6 results.append(entities)
7 return results"Team meeting tomorrow at 2pm with John and Sarah for 1 hour"1{
2 "action": "Team meeting",
3 "date": "tomorrow",
4 "time": "2pm",
5 "attendees": ["John", "Sarah"],
6 "location": null,
7 "duration": "1 hour",
8 "recurrence": null,
9 "notes": null
10}