Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
60d27b1f
Unverified
Commit
60d27b1f
authored
Apr 01, 2022
by
Yih-Dar
Committed by
GitHub
Apr 01, 2022
Browse files
Add code samples for TF speech models (#16494)
Co-authored-by:
ydshieh
<
ydshieh@users.noreply.github.com
>
parent
53a4d6b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
src/transformers/utils/doc.py
src/transformers/utils/doc.py
+63
-0
No files found.
src/transformers/utils/doc.py
View file @
60d27b1f
...
@@ -794,6 +794,67 @@ TF_CAUSAL_LM_SAMPLE = r"""
...
@@ -794,6 +794,67 @@ TF_CAUSAL_LM_SAMPLE = r"""
```
```
"""
"""
TF_SPEECH_BASE_MODEL_SAMPLE
=
r
"""
Example:
```python
>>> from transformers import {processor_class}, {model_class}
>>> from datasets import load_dataset
>>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
>>> dataset = dataset.sort("id")
>>> sampling_rate = dataset.features["audio"].sampling_rate
>>> processor = {processor_class}.from_pretrained("{checkpoint}")
>>> model = {model_class}.from_pretrained("{checkpoint}")
>>> # audio file is decoded on the fly
>>> inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="tf")
>>> outputs = model(**inputs)
>>> last_hidden_states = outputs.last_hidden_state
>>> list(last_hidden_states.shape)
{expected_output}
```
"""
TF_SPEECH_CTC_SAMPLE
=
r
"""
Example:
```python
>>> from transformers import {processor_class}, {model_class}
>>> from datasets import load_dataset
>>> import tensorflow as tf
>>> dataset = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
>>> dataset = dataset.sort("id")
>>> sampling_rate = dataset.features["audio"].sampling_rate
>>> processor = {processor_class}.from_pretrained("{checkpoint}")
>>> model = {model_class}.from_pretrained("{checkpoint}")
>>> # audio file is decoded on the fly
>>> inputs = processor(dataset[0]["audio"]["array"], sampling_rate=sampling_rate, return_tensors="tf")
>>> logits = model(**inputs).logits
>>> predicted_ids = tf.math.argmax(logits, axis=-1)
>>> # transcribe speech
>>> transcription = processor.batch_decode(predicted_ids)
>>> transcription[0]
{expected_output}
```
```python
>>> with processor.as_target_processor():
... inputs["labels"] = processor(dataset[0]["text"], return_tensors="tf").input_ids
>>> # compute loss
>>> loss = model(**inputs).loss
>>> round(float(loss), 2)
{expected_loss}
```
"""
TF_VISION_BASE_MODEL_SAMPLE
=
r
"""
TF_VISION_BASE_MODEL_SAMPLE
=
r
"""
Example:
Example:
...
@@ -848,6 +909,8 @@ TF_SAMPLE_DOCSTRINGS = {
...
@@ -848,6 +909,8 @@ TF_SAMPLE_DOCSTRINGS = {
"MaskedLM"
:
TF_MASKED_LM_SAMPLE
,
"MaskedLM"
:
TF_MASKED_LM_SAMPLE
,
"LMHead"
:
TF_CAUSAL_LM_SAMPLE
,
"LMHead"
:
TF_CAUSAL_LM_SAMPLE
,
"BaseModel"
:
TF_BASE_MODEL_SAMPLE
,
"BaseModel"
:
TF_BASE_MODEL_SAMPLE
,
"SpeechBaseModel"
:
TF_SPEECH_BASE_MODEL_SAMPLE
,
"CTC"
:
TF_SPEECH_CTC_SAMPLE
,
"VisionBaseModel"
:
TF_VISION_BASE_MODEL_SAMPLE
,
"VisionBaseModel"
:
TF_VISION_BASE_MODEL_SAMPLE
,
"ImageClassification"
:
TF_VISION_SEQ_CLASS_SAMPLE
,
"ImageClassification"
:
TF_VISION_SEQ_CLASS_SAMPLE
,
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment