

## inference

The model can be used directly (without a language model) as follows...

Using the [HuggingSound](https://github.com/jonatasgrosman/huggingsound) library:

```python
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
from datasets import load_dataset
import torch
import torchaudio



# load model and processor
processor = Wav2Vec2Processor.from_pretrained("gymeee/demo_code_switching")
model = Wav2Vec2ForCTC.from_pretrained("gymeee/demo_code_switching")

# load speech
speech_array, sampling_rate = torchaudio.load("speech.wav")
# tokenize
input_values = processor(speech_array[0], return_tensors="pt", padding="longest").input_values  # Batch size 1

# retrieve logits
logits = model(input_values).logits

# take argmax and decode
predicted_ids = torch.argmax(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)

transcription
{"language": ["zh"], "license": "apache-2.0", "tags": ["audio", "automatic-speech-recognition", "speech", "xlsr-fine-tuning-week"], "datasets": ["ASCEND"], "metrics": ["cer"]}
transformers pytorch wav2vec2 automatic-speech-recognition audio speech xlsr-fine-tuning-week zh dataset:ASCEND license:apache-2.0 endpoints_compatible has_space region:us
TAGS
#transformers #pytorch #wav2vec2 #automatic-speech-recognition #audio #speech #xlsr-fine-tuning-week #zh #dataset-ASCEND #license-apache-2.0 #endpoints_compatible #has_space #region-us 



## inference

The model can be used directly (without a language model) as follows...

Using the HuggingSound library:

'''python
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
from datasets import load_dataset
import torch
import torchaudio



# load model and processor
processor = Wav2Vec2Processor.from_pretrained("gymeee/demo_code_switching")
model = Wav2Vec2ForCTC.from_pretrained("gymeee/demo_code_switching")

# load speech
speech_array, sampling_rate = URL("URL")
# tokenize
input_values = processor(speech_array[0], return_tensors="pt", padding="longest").input_values  # Batch size 1

# retrieve logits
logits = model(input_values).logits

# take argmax and decode
predicted_ids = URL(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)

transcription
## inference

The model can be used directly (without a language model) as follows...

Using the HuggingSound library:

'''python
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
from datasets import load_dataset
import torch
import torchaudio # load model and processor
processor = Wav2Vec2Processor.from_pretrained("gymeee/demo_code_switching")
model = Wav2Vec2ForCTC.from_pretrained("gymeee/demo_code_switching") # load speech
speech_array, sampling_rate = URL("URL") # tokenize
input_values = processor(speech_array[0], return_tensors="pt", padding="longest").input_values  # Batch size 1 # retrieve logits
logits = model(input_values).logits # take argmax and decode
predicted_ids = URL(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)

transcription
TAGS
#transformers #pytorch #wav2vec2 #automatic-speech-recognition #audio #speech #xlsr-fine-tuning-week #zh #dataset-ASCEND #license-apache-2.0 #endpoints_compatible #has_space #region-us 
 ## inference

The model can be used directly (without a language model) as follows...

Using the HuggingSound library:

'''python
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
from datasets import load_dataset
import torch
import torchaudio # load model and processor
processor = Wav2Vec2Processor.from_pretrained("gymeee/demo_code_switching")
model = Wav2Vec2ForCTC.from_pretrained("gymeee/demo_code_switching") # load speech
speech_array, sampling_rate = URL("URL") # tokenize
input_values = processor(speech_array[0], return_tensors="pt", padding="longest").input_values  # Batch size 1 # retrieve logits
logits = model(input_values).logits # take argmax and decode
predicted_ids = URL(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)

transcription
TAGS
#transformers #pytorch #wav2vec2 #automatic-speech-recognition #audio #speech #xlsr-fine-tuning-week #zh #dataset-ASCEND #license-apache-2.0 #endpoints_compatible #has_space #region-us 
## inference

The model can be used directly (without a language model) as follows...

Using the HuggingSound library:

'''python
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
from datasets import load_dataset
import torch
import torchaudio# load model and processor
processor = Wav2Vec2Processor.from_pretrained("gymeee/demo_code_switching")
model = Wav2Vec2ForCTC.from_pretrained("gymeee/demo_code_switching")# load speech
speech_array, sampling_rate = URL("URL")# tokenize
input_values = processor(speech_array[0], return_tensors="pt", padding="longest").input_values  # Batch size 1# retrieve logits
logits = model(input_values).logits# take argmax and decode
predicted_ids = URL(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)

transcription