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
07b8f249
Unverified
Commit
07b8f249
authored
Nov 17, 2022
by
Nicolas Patry
Committed by
GitHub
Nov 17, 2022
Browse files
Fixing the doctests failures. (#20294)
* Fixing the doctests failures. * Fixup.
parent
0f78529f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
8 deletions
+10
-8
src/transformers/pipelines/__init__.py
src/transformers/pipelines/__init__.py
+5
-3
src/transformers/pipelines/document_question_answering.py
src/transformers/pipelines/document_question_answering.py
+2
-3
src/transformers/pipelines/token_classification.py
src/transformers/pipelines/token_classification.py
+2
-1
src/transformers/pipelines/zero_shot_classification.py
src/transformers/pipelines/zero_shot_classification.py
+1
-1
No files found.
src/transformers/pipelines/__init__.py
View file @
07b8f249
...
@@ -590,15 +590,17 @@ def pipeline(
...
@@ -590,15 +590,17 @@ def pipeline(
>>> from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
>>> from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer
>>> # Sentiment analysis pipeline
>>> # Sentiment analysis pipeline
>>> pipeline("sentiment-analysis")
>>>
analyzer =
pipeline("sentiment-analysis")
>>> # Question answering pipeline, specifying the checkpoint identifier
>>> # Question answering pipeline, specifying the checkpoint identifier
>>> pipeline("question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="bert-base-cased")
>>> oracle = pipeline(
... "question-answering", model="distilbert-base-cased-distilled-squad", tokenizer="bert-base-cased"
... )
>>> # Named entity recognition pipeline, passing in a specific model and tokenizer
>>> # Named entity recognition pipeline, passing in a specific model and tokenizer
>>> model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
>>> model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
>>> tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
>>> tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
>>> pipeline("ner", model=model, tokenizer=tokenizer)
>>>
recognizer =
pipeline("ner", model=model, tokenizer=tokenizer)
```"""
```"""
if
model_kwargs
is
None
:
if
model_kwargs
is
None
:
model_kwargs
=
{}
model_kwargs
=
{}
...
...
src/transformers/pipelines/document_question_answering.py
View file @
07b8f249
...
@@ -112,12 +112,11 @@ class DocumentQuestionAnsweringPipeline(ChunkPipeline):
...
@@ -112,12 +112,11 @@ class DocumentQuestionAnsweringPipeline(ChunkPipeline):
>>> from transformers import pipeline
>>> from transformers import pipeline
>>> document_qa = pipeline(model="impira/layoutlm-document-qa")
>>> document_qa = pipeline(model="impira/layoutlm-document-qa")
>>>
result =
document_qa(
>>> document_qa(
... image="https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png",
... image="https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png",
... question="What is the invoice number?",
... question="What is the invoice number?",
... )
... )
>>> result[0]["answer"]
[{'score': 0.425, 'answer': 'us-001', 'start': 16, 'end': 16}]
'1110212019'
```
```
[Learn more about the basics of using a pipeline in the [pipeline tutorial]](../pipeline_tutorial)
[Learn more about the basics of using a pipeline in the [pipeline tutorial]](../pipeline_tutorial)
...
...
src/transformers/pipelines/token_classification.py
View file @
07b8f249
...
@@ -95,7 +95,8 @@ class TokenClassificationPipeline(Pipeline):
...
@@ -95,7 +95,8 @@ class TokenClassificationPipeline(Pipeline):
>>> token_classifier = pipeline(model="Jean-Baptiste/camembert-ner", aggregation_strategy="simple")
>>> token_classifier = pipeline(model="Jean-Baptiste/camembert-ner", aggregation_strategy="simple")
>>> sentence = "Je m'appelle jean-baptiste et je vis à montréal"
>>> sentence = "Je m'appelle jean-baptiste et je vis à montréal"
>>> token_classifier(sentence)
>>> tokens = token_classifier(sentence)
>>> tokens
[{'entity_group': 'PER', 'score': 0.9931, 'word': 'jean-baptiste', 'start': 12, 'end': 26}, {'entity_group': 'LOC', 'score': 0.998, 'word': 'montréal', 'start': 38, 'end': 47}]
[{'entity_group': 'PER', 'score': 0.9931, 'word': 'jean-baptiste', 'start': 12, 'end': 26}, {'entity_group': 'LOC', 'score': 0.998, 'word': 'montréal', 'start': 38, 'end': 47}]
>>> token = tokens[0]
>>> token = tokens[0]
...
...
src/transformers/pipelines/zero_shot_classification.py
View file @
07b8f249
...
@@ -61,7 +61,7 @@ class ZeroShotClassificationPipeline(ChunkPipeline):
...
@@ -61,7 +61,7 @@ class ZeroShotClassificationPipeline(ChunkPipeline):
>>> from transformers import pipeline
>>> from transformers import pipeline
>>> oracle = pipeline(model="facebook/bart-large-mnli")
>>> oracle = pipeline(model="facebook/bart-large-mnli")
>>>
answers =
oracle(
>>> oracle(
... "I have a problem with my iphone that needs to be resolved asap!!",
... "I have a problem with my iphone that needs to be resolved asap!!",
... candidate_labels=["urgent", "not urgent", "phone", "tablet", "computer"],
... candidate_labels=["urgent", "not urgent", "phone", "tablet", "computer"],
... )
... )
...
...
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