From 22731a654e6a24ca4ca6ff0da603dac62d55307a Mon Sep 17 00:00:00 2001 From: hanouticelina <36770234+hanouticelina@users.noreply.github.com> Date: Fri, 27 Dec 2024 03:05:02 +0000 Subject: [PATCH] Update API inference documentation (automated) --- changed_files.txt | 6 ++ .../api-inference/tasks/question-answering.md | 1 - .../tasks/table-question-answering.md | 7 +- .../tasks/text-classification.md | 68 ++++++++----------- .../tasks/zero-shot-classification.md | 1 - scripts/api-inference/package.json | 2 +- scripts/api-inference/pnpm-lock.yaml | 10 +-- 7 files changed, 43 insertions(+), 52 deletions(-) create mode 100644 changed_files.txt diff --git a/changed_files.txt b/changed_files.txt new file mode 100644 index 000000000..e7ee33f6d --- /dev/null +++ b/changed_files.txt @@ -0,0 +1,6 @@ +docs/api-inference/tasks/question-answering.md +docs/api-inference/tasks/table-question-answering.md +docs/api-inference/tasks/text-classification.md +docs/api-inference/tasks/zero-shot-classification.md +scripts/api-inference/package.json +scripts/api-inference/pnpm-lock.yaml diff --git a/docs/api-inference/tasks/question-answering.md b/docs/api-inference/tasks/question-answering.md index a63730d69..0222d8549 100644 --- a/docs/api-inference/tasks/question-answering.md +++ b/docs/api-inference/tasks/question-answering.md @@ -26,7 +26,6 @@ For more details about the `question-answering` task, check out its [dedicated p - [deepset/roberta-base-squad2](https://huggingface.co/deepset/roberta-base-squad2): A robust baseline model for most question answering domains. - [distilbert/distilbert-base-cased-distilled-squad](https://huggingface.co/distilbert/distilbert-base-cased-distilled-squad): Small yet robust model that can answer questions. -- [google/tapas-base-finetuned-wtq](https://huggingface.co/google/tapas-base-finetuned-wtq): A special model that can answer questions from tables. Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=question-answering&sort=trending). diff --git a/docs/api-inference/tasks/table-question-answering.md b/docs/api-inference/tasks/table-question-answering.md index 55608ed25..6d1c99bfb 100644 --- a/docs/api-inference/tasks/table-question-answering.md +++ b/docs/api-inference/tasks/table-question-answering.md @@ -24,7 +24,6 @@ For more details about the `table-question-answering` task, check out its [dedic ### Recommended models -- [google/tapas-base-finetuned-wtq](https://huggingface.co/google/tapas-base-finetuned-wtq): A robust table question answering model. Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=table-question-answering&sort=trending). @@ -35,7 +34,7 @@ Explore all available models and find the one that suits you best [here](https:/ ```bash -curl https://api-inference.huggingface.co/models/google/tapas-base-finetuned-wtq \ +curl https://api-inference.huggingface.co/models/ \ -X POST \ -d '{"inputs": { "query": "How many stars does the transformers repository have?", "table": { "Repository": ["Transformers", "Datasets", "Tokenizers"], "Stars": ["36542", "4512", "3934"], "Contributors": ["651", "77", "34"], "Programming language": [ "Python", "Python", "Rust, Python and NodeJS" ] } }}' \ -H 'Content-Type: application/json' \ @@ -47,7 +46,7 @@ curl https://api-inference.huggingface.co/models/google/tapas-base-finetuned-wtq ```py import requests -API_URL = "https://api-inference.huggingface.co/models/google/tapas-base-finetuned-wtq" +API_URL = "https://api-inference.huggingface.co/models/" headers = {"Authorization": "Bearer hf_***"} def query(payload): @@ -78,7 +77,7 @@ To use the Python client, see `huggingface_hub`'s [package reference](https://hu ```js async function query(data) { const response = await fetch( - "https://api-inference.huggingface.co/models/google/tapas-base-finetuned-wtq", + "https://api-inference.huggingface.co/models/", { headers: { Authorization: "Bearer hf_***", diff --git a/docs/api-inference/tasks/text-classification.md b/docs/api-inference/tasks/text-classification.md index f90a9d5e8..83cf43653 100644 --- a/docs/api-inference/tasks/text-classification.md +++ b/docs/api-inference/tasks/text-classification.md @@ -37,67 +37,54 @@ Explore all available models and find the one that suits you best [here](https:/ - ```bash -curl https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1 \ - -X POST \ - -d '{"inputs": [{"text": "What is Paris?", "text_pair": "Paris is the capital of France"}]}' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer hf_***' +curl https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english \ + -X POST \ + -d '{"inputs": "I like you. I love you"}' \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer hf_***' ``` - - -```python +```py import requests -API_URL = "https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1" +API_URL = "https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english" headers = {"Authorization": "Bearer hf_***"} def query(payload): - response = requests.post(API_URL, headers=headers, json=payload) - return response.json() - + response = requests.post(API_URL, headers=headers, json=payload) + return response.json() + output = query({ - "inputs": [ - {"text": "What is Paris?", "text_pair": "Paris is the capital of France"}, - {"text": "What is Paris?", "text_pair": "London is the capital of England"} - ] + "inputs": "I like you. I love you", }) ``` To use the Python client, see `huggingface_hub`'s [package reference](https://huggingface.co/docs/huggingface_hub/package_reference/inference_client#huggingface_hub.InferenceClient.text_classification). - - -```javascript +```js async function query(data) { - const response = await fetch( - "https://api-inference.huggingface.co/models/mixedbread-ai/mxbai-rerank-base-v1", - { - headers: { - Authorization: "Bearer hf_***", - "Content-Type": "application/json", - }, - method: "POST", - body: JSON.stringify(data), - } - ); - const result = await response.json(); - return result; + const response = await fetch( + "https://api-inference.huggingface.co/models/distilbert/distilbert-base-uncased-finetuned-sst-2-english", + { + headers: { + Authorization: "Bearer hf_***", + "Content-Type": "application/json", + }, + method: "POST", + body: JSON.stringify(data), + } + ); + const result = await response.json(); + return result; } -query({ - "inputs": [ - {"text": "What is Paris?", "text_pair": "Paris is the capital of France"}, - {"text": "What is Paris?", "text_pair": "London is the capital of England"} - ] -}).then((response) => { - console.log(JSON.stringify(response)); +query({"inputs": "I like you. I love you"}).then((response) => { + console.log(JSON.stringify(response)); }); ``` @@ -107,6 +94,7 @@ To use the JavaScript client, see `huggingface.js`'s [package reference](https:/ + ### API specification #### Request diff --git a/docs/api-inference/tasks/zero-shot-classification.md b/docs/api-inference/tasks/zero-shot-classification.md index 5f9caa07a..a20d5bc9f 100644 --- a/docs/api-inference/tasks/zero-shot-classification.md +++ b/docs/api-inference/tasks/zero-shot-classification.md @@ -25,7 +25,6 @@ For more details about the `zero-shot-classification` task, check out its [dedic ### Recommended models - [facebook/bart-large-mnli](https://huggingface.co/facebook/bart-large-mnli): Powerful zero-shot text classification model. -- [MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7](https://huggingface.co/MoritzLaurer/mDeBERTa-v3-base-xnli-multilingual-nli-2mil7): Powerful zero-shot multilingual text classification model that can accomplish multiple tasks. Explore all available models and find the one that suits you best [here](https://huggingface.co/models?inference=warm&pipeline_tag=zero-shot-classification&sort=trending). diff --git a/scripts/api-inference/package.json b/scripts/api-inference/package.json index 22d2d7d6c..b29ee0bb8 100644 --- a/scripts/api-inference/package.json +++ b/scripts/api-inference/package.json @@ -14,7 +14,7 @@ "author": "", "license": "ISC", "dependencies": { - "@huggingface/tasks": "^0.13.11", + "@huggingface/tasks": "^0.13.13", "@types/node": "^22.5.0", "handlebars": "^4.7.8", "node": "^20.17.0", diff --git a/scripts/api-inference/pnpm-lock.yaml b/scripts/api-inference/pnpm-lock.yaml index df282c58f..100f81814 100644 --- a/scripts/api-inference/pnpm-lock.yaml +++ b/scripts/api-inference/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@huggingface/tasks': - specifier: ^0.13.11 - version: 0.13.11 + specifier: ^0.13.13 + version: 0.13.13 '@types/node': specifier: ^22.5.0 version: 22.5.0 @@ -186,8 +186,8 @@ packages: cpu: [x64] os: [win32] - '@huggingface/tasks@0.13.11': - resolution: {integrity: sha512-3fAiLfrUTz2RSt8mTmumxAC9+6fQIPYUXGM6/72cW6xVLIFYBrJElsHDaoHUr/I/KouMEzwJ6MBaTS7mRduBjA==} + '@huggingface/tasks@0.13.13': + resolution: {integrity: sha512-jaU91/x9mn3q1pwHMzpUiXICqME56LgDgza/nyt4h3Jp6k84YW931YFK5ri32qBDHmtjn/1dR4OMw85+dx87dA==} '@jridgewell/resolve-uri@3.1.2': resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} @@ -404,7 +404,7 @@ snapshots: '@esbuild/win32-x64@0.23.1': optional: true - '@huggingface/tasks@0.13.11': {} + '@huggingface/tasks@0.13.13': {} '@jridgewell/resolve-uri@3.1.2': {}