|
| 1 | +# Inference Toolkit API |
| 2 | + |
| 3 | +## Supported tasks |
| 4 | + |
| 5 | +The Inference Toolkit accepts inputs in the `inputs` key, and supports additional [`pipelines`](https://huggingface.co/docs/transformers/main_classes/pipelines) parameters in the `parameters` key. You can provide any of the supported `kwargs` from `pipelines` as `parameters`. |
| 6 | + |
| 7 | +Tasks supported by the Inference Toolkit API include: |
| 8 | + |
| 9 | +- **`text-classification`** |
| 10 | +- **`sentiment-analysis`** |
| 11 | +- **`token-classification`** |
| 12 | +- **`feature-extraction`** |
| 13 | +- **`fill-mask`** |
| 14 | +- **`summarization`** |
| 15 | +- **`translation_xx_to_yy`** |
| 16 | +- **`text2text-generation`** |
| 17 | +- **`text-generation`** |
| 18 | +- **`audio-classificatin`** |
| 19 | +- **`automatic-speech-recognition`** |
| 20 | +- **`conversational`** |
| 21 | +- **`image-classification`** |
| 22 | +- **`image-segmentation`** |
| 23 | +- **`object-detection`** |
| 24 | +- **`table-question-answering`** |
| 25 | +- **`zero-shot-classification`** |
| 26 | +- **`zero-shot-image-classification`** |
| 27 | + |
| 28 | + |
| 29 | +See the following request examples for some of the tasks: |
| 30 | + |
| 31 | +**`text-classification`** |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "inputs": "This sound track was beautiful! It paints the senery in your mind so well I would recomend it |
| 36 | + even to people who hate vid. game music!" |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +**`sentiment-analysis`** |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "inputs": "Don't waste your time. We had two different people come to our house to give us estimates for |
| 45 | +a deck (one of them the OWNER). Both times, we never heard from them. Not a call, not the estimate, nothing." |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +**`token-classification`** |
| 50 | + |
| 51 | +```json |
| 52 | +{ |
| 53 | + "inputs": "My name is Sylvain and I work at Hugging Face in Brooklyn." |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +**`question-answering`** |
| 58 | + |
| 59 | +```json |
| 60 | +{ |
| 61 | + "inputs": { |
| 62 | + "question": "What is used for inference?", |
| 63 | + "context": "My Name is Philipp and I live in Nuremberg. This model is used with sagemaker for inference." |
| 64 | + } |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +**`zero-shot-classification`** |
| 69 | + |
| 70 | +```json |
| 71 | +{ |
| 72 | + "inputs": "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!", |
| 73 | + "parameters": { |
| 74 | + "candidate_labels": ["refund", "legal", "faq"] |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +**`table-question-answering`** |
| 80 | + |
| 81 | +```json |
| 82 | +{ |
| 83 | + "inputs": { |
| 84 | + "query": "How many stars does the transformers repository have?", |
| 85 | + "table": { |
| 86 | + "Repository": ["Transformers", "Datasets", "Tokenizers"], |
| 87 | + "Stars": ["36542", "4512", "3934"], |
| 88 | + "Contributors": ["651", "77", "34"], |
| 89 | + "Programming language": ["Python", "Python", "Rust, Python and NodeJS"] |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +**`parameterized-request`** |
| 96 | + |
| 97 | +```json |
| 98 | +{ |
| 99 | + "inputs": "Hugging Face, the winner of VentureBeat’s Innovation in Natural Language Process/Understanding Award for 2021, is looking to level the playing field. The team, launched by Clément Delangue and Julien Chaumond in 2016, was recognized for its work in democratizing NLP, the global market value for which is expected to hit $35.1 billion by 2026. This week, Google’s former head of Ethical AI Margaret Mitchell joined the team.", |
| 100 | + "parameters": { |
| 101 | + "repetition_penalty": 4.0, |
| 102 | + "length_penalty": 1.5 |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +## Environment variables |
| 108 | + |
| 109 | +The Inference Toolkit implements various additional environment variables to simplify deployment. A complete list of Hugging Face specific environment variables is shown below: |
| 110 | + |
| 111 | +**`HF_TASK`** |
| 112 | + |
| 113 | +`HF_TASK` defines the task for the 🤗 Transformers pipeline used . See [here](https://huggingface.co/docs/transformers/main_classes/pipelines) for a complete list of tasks. |
| 114 | + |
| 115 | +```bash |
| 116 | +HF_TASK="question-answering" |
| 117 | +``` |
| 118 | + |
| 119 | +**`HF_MODEL_ID`** |
| 120 | + |
| 121 | +`HF_MODEL_ID` defines the model ID which is automatically loaded from [hf.co/models](https://huggingface.co/models) when creating a SageMaker endpoint. All of the 🤗 Hub's 10,000+ models are available through this environment variable. |
| 122 | + |
| 123 | +```bash |
| 124 | +HF_MODEL_ID="distilbert-base-uncased-finetuned-sst-2-english" |
| 125 | +``` |
| 126 | + |
| 127 | +**`HF_MODEL_REVISION`** |
| 128 | + |
| 129 | +`HF_MODEL_REVISION` is an extension to `HF_MODEL_ID` and allows you to define or pin a model revision to make sure you always load the same model on your SageMaker endpoint. |
| 130 | + |
| 131 | +```bash |
| 132 | +HF_MODEL_REVISION="03b4d196c19d0a73c7e0322684e97db1ec397613" |
| 133 | +``` |
| 134 | + |
| 135 | +**`HF_API_TOKEN`** |
| 136 | + |
| 137 | +`HF_API_TOKEN` defines your Hugging Face authorization token. The `HF_API_TOKEN` is used as a HTTP bearer authorization for remote files like private models. You can find your token under [Settings](https://huggingface.co/settings/tokens) of your Hugging Face account. |
| 138 | + |
| 139 | +```bash |
| 140 | +HF_API_TOKEN="api_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
| 141 | +``` |
0 commit comments