import google.generativeai as genai import ollama from titlecase import titlecase
audrey.feldroy.com
The experimental notebooks of Audrey M. Roy Greenfeld. This website and all its notebooks are open-source at github.com/audreyfeldroy/audrey.feldroy.com
# Building a Better Title-Caser, Part 2: Using an Ollama Modelfile
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.
Setup
Create an Mistral-Based Model With an Ollama Modelfile
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.
Future Topics
- Compare the different title case functions more, using other test cases.
- See if I can get great performance out of another more lightweight local model.
© 2024-2025 Audrey M. Roy Greenfeld