by Audrey M. Roy Greenfeld | Sat, Feb 15, 2025
Here I create a local titlecase model based on Mistral, using a local Ollama modelfile and a solid prompt.
import google.generativeai as genai import ollama from titlecase import titlecase
For better title casing, perhaps I can create an Ollama modelfile starting with a good model like mistral. I put this into tc.modelfile
:
FROM mistral
PARAMETER temperature 0.1
PARAMETER num_ctx 512
# System prompt to specialize the model
SYSTEM """You are a title case expert. You follow these rules:
- Capitalize brand names correctly (e.g. iPhone, iPad)
- Keep acronyms in all caps (e.g. PDF, HTML)
- Hyphenated words have first letter of each word capitalized (e.g. E-Mail)
- Don't capitalize articles/conjunctions unless first word
Return only the properly title-cased text with no explanation."""
I created and used this model with:
ollama create titlecase -f tc.modelfile
I can see my new model with:
(uv) ~ % ollama list
NAME ID SIZE MODIFIED
titlecase:latest 255c41b01169 4.1 GB 14 minutes ago
I then defined a titlecase function with it:
def tc(s): return ollama.chat(model='titlecase', messages=[{ 'role': 'user', 'content': f"Convert to title case: {s}" }])['message']['content'].strip()
tc("iphone and e-mail tips for pdfs")
tc("iphone and email tips for pdfs")
The results are great. Of course this is just one test case.