Automatic Speech Recognition
Transformers
Safetensors
PyTorch
arkasr
text-generation
speech
audio
ark-asr
custom_code
Eval Results
Instructions to use Audio8/ARK-ASR-0.6B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Audio8/ARK-ASR-0.6B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="Audio8/ARK-ASR-0.6B", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Audio8/ARK-ASR-0.6B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md
Browse files
README.md
CHANGED
|
@@ -118,6 +118,19 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 118 |
torch_dtype=torch_dtype,
|
| 119 |
attn_implementation="sdpa",
|
| 120 |
).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
conversation = [
|
| 123 |
{
|
|
@@ -133,20 +146,25 @@ inputs = processor.apply_chat_template(
|
|
| 133 |
conversation,
|
| 134 |
add_generation_prompt=True,
|
| 135 |
return_tensors="pt",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
)
|
| 137 |
inputs = inputs.to(device)
|
| 138 |
if "audios" in inputs:
|
| 139 |
inputs["audios"] = inputs["audios"].to(dtype=torch_dtype)
|
| 140 |
|
| 141 |
-
bad_words_ids =
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
| 150 |
decoded_outputs = tokenizer.batch_decode(
|
| 151 |
outputs[:, inputs.input_ids.shape[1] :],
|
| 152 |
skip_special_tokens=True,
|
|
|
|
| 118 |
torch_dtype=torch_dtype,
|
| 119 |
attn_implementation="sdpa",
|
| 120 |
).to(device)
|
| 121 |
+
model.eval()
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def build_bad_words_ids(tokenizer):
|
| 125 |
+
eos_ids = tokenizer.eos_token_id
|
| 126 |
+
keep_ids = {eos_ids} if isinstance(eos_ids, int) else set(eos_ids or [])
|
| 127 |
+
bad_ids = set(tokenizer.all_special_ids) - keep_ids
|
| 128 |
+
bad_ids.update(
|
| 129 |
+
token_id
|
| 130 |
+
for token, token_id in tokenizer.get_added_vocab().items()
|
| 131 |
+
if token.startswith("<") and token.endswith(">") and token_id not in keep_ids
|
| 132 |
+
)
|
| 133 |
+
return [[token_id] for token_id in sorted(bad_ids)]
|
| 134 |
|
| 135 |
conversation = [
|
| 136 |
{
|
|
|
|
| 146 |
conversation,
|
| 147 |
add_generation_prompt=True,
|
| 148 |
return_tensors="pt",
|
| 149 |
+
sampling_rate=16000,
|
| 150 |
+
audio_padding="longest",
|
| 151 |
+
text_kwargs={"padding": "longest"},
|
| 152 |
+
audio_max_length=30 * 16000,
|
| 153 |
)
|
| 154 |
inputs = inputs.to(device)
|
| 155 |
if "audios" in inputs:
|
| 156 |
inputs["audios"] = inputs["audios"].to(dtype=torch_dtype)
|
| 157 |
|
| 158 |
+
bad_words_ids = build_bad_words_ids(tokenizer)
|
| 159 |
+
with torch.inference_mode():
|
| 160 |
+
outputs = model.generate(
|
| 161 |
+
**inputs,
|
| 162 |
+
do_sample=False,
|
| 163 |
+
max_new_tokens=256,
|
| 164 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 165 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 166 |
+
bad_words_ids=bad_words_ids,
|
| 167 |
+
)
|
| 168 |
decoded_outputs = tokenizer.batch_decode(
|
| 169 |
outputs[:, inputs.input_ids.shape[1] :],
|
| 170 |
skip_special_tokens=True,
|