Delete README.md
Browse files
README.md
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
library_name: transformers
|
| 3 |
-
license: gpl-3.0
|
| 4 |
-
language:
|
| 5 |
-
- as
|
| 6 |
-
- bn
|
| 7 |
-
- brx
|
| 8 |
-
- doi
|
| 9 |
-
- gom
|
| 10 |
-
- gu
|
| 11 |
-
- en
|
| 12 |
-
- hi
|
| 13 |
-
- kn
|
| 14 |
-
- ks
|
| 15 |
-
- mai
|
| 16 |
-
- ml
|
| 17 |
-
- mni
|
| 18 |
-
- mr
|
| 19 |
-
- ne
|
| 20 |
-
- or
|
| 21 |
-
- pa
|
| 22 |
-
- sa
|
| 23 |
-
- sat
|
| 24 |
-
- sd
|
| 25 |
-
- ta
|
| 26 |
-
- te
|
| 27 |
-
- ur
|
| 28 |
-
base_model:
|
| 29 |
-
- google/gemma-3-4b-it
|
| 30 |
-
base_model_relation: finetune
|
| 31 |
-
pipeline_tag: translation
|
| 32 |
-
---
|
| 33 |
-
|
| 34 |
-
# Sarvam-Translate
|
| 35 |
-
<p align="center">
|
| 36 |
-
<a href="https://dashboard.sarvam.ai/translate"
|
| 37 |
-
target="_blank" rel="noopener noreferrer">
|
| 38 |
-
<img
|
| 39 |
-
src="https://img.shields.io/badge/🚀 Try on Sarvam Playground-1488CC?style=for-the-badge&logo=rocket"
|
| 40 |
-
alt="Try on Sarvam Playground"
|
| 41 |
-
/>
|
| 42 |
-
</a>
|
| 43 |
-
</p>
|
| 44 |
-
Sarvam-Translate is an advanced translation model built by Sarvam AI in partnership with AI4Bharat, specifically designed for comprehensive, document-level translation across the 22 official Indian languages, built on Gemma3-4B-IT. It addresses modern translation needs by moving beyond isolated sentences to handle long-context inputs, diverse content types, and various formats. Sarvam-Translate aims to provide high-quality, contextually aware translations for Indian languages, which have traditionally lagged behind high-resource languages in LLM performance.
|
| 45 |
-
|
| 46 |
-
Learn more about Sarvam-Translate in our detailed [blog post](https://www.sarvam.ai/blogs/sarvam-translate).
|
| 47 |
-
|
| 48 |
-
## Key Features
|
| 49 |
-
- **Comprehensive Indian Language Support**: Focus on the 22 official Indian languages, ensuring nuanced and accurate translations.
|
| 50 |
-
- **Advanced Document-Level Translation**: Translates entire documents, web pages, speeches, textbooks, and scientific articles, not just isolated sentences. Maximum context length: 8k tokens
|
| 51 |
-
- **Versatile Format Handling**: Processes a wide array of input formats, including markdown, digitized content (handling OCR errors), documents with embedded math and chemistry equations, and code files (translating only comments).
|
| 52 |
-
- **Context-Aware & Inclusive**: Engineered to respect different contexts, formats, styles (formal/informal), and ensure inclusivity (e.g., appropriate gender attribution).
|
| 53 |
-
|
| 54 |
-
## Supported languages list
|
| 55 |
-
|
| 56 |
-
`Assamese`, `Bengali`, `Bodo`, `Dogri`, `Gujarati`, `English`, `Hindi`, `Kannada`, `Kashmiri`, `Konkani`, `Maithili`, `Malayalam`, `Manipuri`, `Marathi`, `Nepali`, `Odia`, `Punjabi`, `Sanskrit`, `Santali`, `Sindhi`, `Tamil`, `Telugu`, `Urdu`
|
| 57 |
-
|
| 58 |
-
## Quickstart
|
| 59 |
-
The following code snippet demonstrates how to use Sarvam-Translate using Transformers.
|
| 60 |
-
```python
|
| 61 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 62 |
-
|
| 63 |
-
model_name = "sarvamai/sarvam-translate"
|
| 64 |
-
|
| 65 |
-
# Load tokenizer and model
|
| 66 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 67 |
-
model = AutoModelForCausalLM.from_pretrained(model_name).to('cuda:0')
|
| 68 |
-
|
| 69 |
-
# Translation task
|
| 70 |
-
tgt_lang = "Hindi"
|
| 71 |
-
input_txt = "Be the change you wish to see in the world."
|
| 72 |
-
|
| 73 |
-
# Chat-style message prompt
|
| 74 |
-
messages = [
|
| 75 |
-
{"role": "system", "content": f"Translate the text below to {tgt_lang}."},
|
| 76 |
-
{"role": "user", "content": input_txt}
|
| 77 |
-
]
|
| 78 |
-
|
| 79 |
-
# Apply chat template to structure the conversation
|
| 80 |
-
text = tokenizer.apply_chat_template(
|
| 81 |
-
messages,
|
| 82 |
-
tokenize=False,
|
| 83 |
-
add_generation_prompt=True
|
| 84 |
-
)
|
| 85 |
-
|
| 86 |
-
# Tokenize and move input to model device
|
| 87 |
-
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 88 |
-
|
| 89 |
-
# Generate the output
|
| 90 |
-
generated_ids = model.generate(
|
| 91 |
-
**model_inputs,
|
| 92 |
-
max_new_tokens=1024,
|
| 93 |
-
do_sample=True,
|
| 94 |
-
temperature=0.01,
|
| 95 |
-
num_return_sequences=1
|
| 96 |
-
)
|
| 97 |
-
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
|
| 98 |
-
output_text = tokenizer.decode(output_ids, skip_special_tokens=True)
|
| 99 |
-
|
| 100 |
-
print("Input:", input_txt)
|
| 101 |
-
print("Translation:", output_text)
|
| 102 |
-
|
| 103 |
-
```
|
| 104 |
-
|
| 105 |
-
## vLLM Deployment
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
### Server:
|
| 109 |
-
```bash
|
| 110 |
-
vllm serve sarvamai/sarvam-translate --port 8000 --dtype bfloat16 --max-model-len 8192
|
| 111 |
-
```
|
| 112 |
-
|
| 113 |
-
### Client:
|
| 114 |
-
```python
|
| 115 |
-
from openai import OpenAI
|
| 116 |
-
|
| 117 |
-
# Modify OpenAI's API key and API base to use vLLM's API server.
|
| 118 |
-
openai_api_key = "EMPTY"
|
| 119 |
-
openai_api_base = "http://localhost:8000/v1"
|
| 120 |
-
|
| 121 |
-
client = OpenAI(
|
| 122 |
-
api_key=openai_api_key,
|
| 123 |
-
base_url=openai_api_base,
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
models = client.models.list()
|
| 127 |
-
model = models.data[0].id
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
tgt_lang = 'Hindi'
|
| 131 |
-
input_txt = 'Be the change you wish to see in the world.'
|
| 132 |
-
messages = [{"role": "system", "content": f"Translate the text below to {tgt_lang}."}, {"role": "user", "content": input_txt}]
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
response = client.chat.completions.create(model=model, messages=messages, temperature=0.01)
|
| 136 |
-
output_text = response.choices[0].message.content
|
| 137 |
-
|
| 138 |
-
print("Input:", input_txt)
|
| 139 |
-
print("Translation:", output_text)
|
| 140 |
-
```
|
| 141 |
-
|
| 142 |
-
## With Sarvam APIs
|
| 143 |
-
|
| 144 |
-
Refer our [python client documentation](https://pypi.org/project/sarvamai/).
|
| 145 |
-
|
| 146 |
-
Sample code:
|
| 147 |
-
|
| 148 |
-
```python
|
| 149 |
-
from sarvamai import SarvamAI
|
| 150 |
-
client = SarvamAI()
|
| 151 |
-
response = client.text.translate(
|
| 152 |
-
input="Be the change you wish to see in the world.",
|
| 153 |
-
source_language_code="en-IN",
|
| 154 |
-
target_language_code="hi-IN",
|
| 155 |
-
speaker_gender="Male",
|
| 156 |
-
model="sarvam-translate:v1",
|
| 157 |
-
)
|
| 158 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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