Instructions to use Timegravity/tamil-lm-2b-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Timegravity/tamil-lm-2b-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Timegravity/tamil-lm-2b-base") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Timegravity/tamil-lm-2b-base") model = AutoModelForMultimodalLM.from_pretrained("Timegravity/tamil-lm-2b-base", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Timegravity/tamil-lm-2b-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Timegravity/tamil-lm-2b-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Timegravity/tamil-lm-2b-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Timegravity/tamil-lm-2b-base
- SGLang
How to use Timegravity/tamil-lm-2b-base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Timegravity/tamil-lm-2b-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Timegravity/tamil-lm-2b-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Timegravity/tamil-lm-2b-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Timegravity/tamil-lm-2b-base", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Timegravity/tamil-lm-2b-base with Docker Model Runner:
docker model run hf.co/Timegravity/tamil-lm-2b-base
Upload tools/guard_v3.py with huggingface_hub
Browse files- tools/guard_v3.py +33 -0
tools/guard_v3.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Guard v3 runtime: binary unsafe model + category head + per-category thresholds (sexual and slur lower).
|
| 2 |
+
Same interface as guard.Guard / guard_small.SmallGuard. Loaded by guard.Guard() when data/index/guard_v3.pkl exists
|
| 3 |
+
(GUARD_BACKEND=v2 forces the previous small guard)."""
|
| 4 |
+
import os, pickle
|
| 5 |
+
|
| 6 |
+
CATS = ("sexual", "slur", "profanity", "violence", "self_harm", "other")
|
| 7 |
+
|
| 8 |
+
def score_texts(pkg, texts):
|
| 9 |
+
"""Returns (labels, categories, p_unsafe) applying the category-aware thresholds."""
|
| 10 |
+
p = pkg["binary"].predict_proba(list(texts))[:, 1]
|
| 11 |
+
cats = list(pkg["category"].predict(list(texts)))
|
| 12 |
+
thr = pkg.get("category_thresholds", {}); g = float(pkg.get("general_threshold", 0.5))
|
| 13 |
+
labels = []
|
| 14 |
+
for pi, c in zip(p, cats):
|
| 15 |
+
t = float(thr.get(c, g))
|
| 16 |
+
labels.append("unsafe" if pi >= t else "safe")
|
| 17 |
+
return labels, cats, p
|
| 18 |
+
|
| 19 |
+
class GuardV3:
|
| 20 |
+
def __init__(self, enabled=True, path="data/index/guard_v3.pkl", **kw):
|
| 21 |
+
self.enabled = enabled; self.path = path; self._pkg = None; self.model_name = "guard_v3(tfidf-lr+category)"
|
| 22 |
+
def _load(self):
|
| 23 |
+
if self._pkg is None: self._pkg = pickle.load(open(self.path, "rb"))
|
| 24 |
+
def classify_batch(self, texts, role="user", prompts=None):
|
| 25 |
+
if not self.enabled: return [{"label": "safe", "categories": [], "raw": "", "disabled": True} for _ in texts]
|
| 26 |
+
self._load(); labels, cats, p = score_texts(self._pkg, texts)
|
| 27 |
+
thr = self._pkg.get("category_thresholds", {}); g = self._pkg.get("general_threshold", 0.5)
|
| 28 |
+
return [{"label": l, "categories": [c] if l == "unsafe" else [], "raw": f"p_unsafe={pi:.3f} cat={c} thr={thr.get(c, g)}"} for l, c, pi in zip(labels, cats, p)]
|
| 29 |
+
def classify(self, text, role="user", prompt=None):
|
| 30 |
+
return self.classify_batch([text], role, [prompt])[0]
|
| 31 |
+
def refusal_text(self, lang):
|
| 32 |
+
from guard import refusal_text
|
| 33 |
+
return refusal_text(lang)
|