@huggingface/tasks 0.13.1-test → 0.13.1-test2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/package.json +4 -2
  2. package/src/dataset-libraries.ts +89 -0
  3. package/src/default-widget-inputs.ts +718 -0
  4. package/src/gguf.ts +40 -0
  5. package/src/hardware.ts +482 -0
  6. package/src/index.ts +59 -0
  7. package/src/library-to-tasks.ts +76 -0
  8. package/src/local-apps.ts +412 -0
  9. package/src/model-data.ts +149 -0
  10. package/src/model-libraries-downloads.ts +18 -0
  11. package/src/model-libraries-snippets.ts +1128 -0
  12. package/src/model-libraries.ts +820 -0
  13. package/src/pipelines.ts +698 -0
  14. package/src/snippets/common.ts +39 -0
  15. package/src/snippets/curl.spec.ts +94 -0
  16. package/src/snippets/curl.ts +120 -0
  17. package/src/snippets/index.ts +7 -0
  18. package/src/snippets/inputs.ts +167 -0
  19. package/src/snippets/js.spec.ts +148 -0
  20. package/src/snippets/js.ts +305 -0
  21. package/src/snippets/python.spec.ts +144 -0
  22. package/src/snippets/python.ts +321 -0
  23. package/src/snippets/types.ts +16 -0
  24. package/src/tasks/audio-classification/about.md +86 -0
  25. package/src/tasks/audio-classification/data.ts +81 -0
  26. package/src/tasks/audio-classification/inference.ts +52 -0
  27. package/src/tasks/audio-classification/spec/input.json +35 -0
  28. package/src/tasks/audio-classification/spec/output.json +11 -0
  29. package/src/tasks/audio-to-audio/about.md +56 -0
  30. package/src/tasks/audio-to-audio/data.ts +70 -0
  31. package/src/tasks/automatic-speech-recognition/about.md +90 -0
  32. package/src/tasks/automatic-speech-recognition/data.ts +82 -0
  33. package/src/tasks/automatic-speech-recognition/inference.ts +160 -0
  34. package/src/tasks/automatic-speech-recognition/spec/input.json +35 -0
  35. package/src/tasks/automatic-speech-recognition/spec/output.json +38 -0
  36. package/src/tasks/chat-completion/inference.ts +322 -0
  37. package/src/tasks/chat-completion/spec/input.json +350 -0
  38. package/src/tasks/chat-completion/spec/output.json +206 -0
  39. package/src/tasks/chat-completion/spec/stream_output.json +213 -0
  40. package/src/tasks/common-definitions.json +100 -0
  41. package/src/tasks/depth-estimation/about.md +45 -0
  42. package/src/tasks/depth-estimation/data.ts +70 -0
  43. package/src/tasks/depth-estimation/inference.ts +35 -0
  44. package/src/tasks/depth-estimation/spec/input.json +25 -0
  45. package/src/tasks/depth-estimation/spec/output.json +16 -0
  46. package/src/tasks/document-question-answering/about.md +53 -0
  47. package/src/tasks/document-question-answering/data.ts +85 -0
  48. package/src/tasks/document-question-answering/inference.ts +110 -0
  49. package/src/tasks/document-question-answering/spec/input.json +85 -0
  50. package/src/tasks/document-question-answering/spec/output.json +36 -0
  51. package/src/tasks/feature-extraction/about.md +72 -0
  52. package/src/tasks/feature-extraction/data.ts +57 -0
  53. package/src/tasks/feature-extraction/inference.ts +40 -0
  54. package/src/tasks/feature-extraction/spec/input.json +47 -0
  55. package/src/tasks/feature-extraction/spec/output.json +15 -0
  56. package/src/tasks/fill-mask/about.md +51 -0
  57. package/src/tasks/fill-mask/data.ts +79 -0
  58. package/src/tasks/fill-mask/inference.ts +62 -0
  59. package/src/tasks/fill-mask/spec/input.json +38 -0
  60. package/src/tasks/fill-mask/spec/output.json +29 -0
  61. package/src/tasks/image-classification/about.md +50 -0
  62. package/src/tasks/image-classification/data.ts +88 -0
  63. package/src/tasks/image-classification/inference.ts +52 -0
  64. package/src/tasks/image-classification/spec/input.json +35 -0
  65. package/src/tasks/image-classification/spec/output.json +11 -0
  66. package/src/tasks/image-feature-extraction/about.md +23 -0
  67. package/src/tasks/image-feature-extraction/data.ts +59 -0
  68. package/src/tasks/image-segmentation/about.md +63 -0
  69. package/src/tasks/image-segmentation/data.ts +99 -0
  70. package/src/tasks/image-segmentation/inference.ts +69 -0
  71. package/src/tasks/image-segmentation/spec/input.json +45 -0
  72. package/src/tasks/image-segmentation/spec/output.json +26 -0
  73. package/src/tasks/image-text-to-text/about.md +76 -0
  74. package/src/tasks/image-text-to-text/data.ts +102 -0
  75. package/src/tasks/image-to-3d/about.md +62 -0
  76. package/src/tasks/image-to-3d/data.ts +75 -0
  77. package/src/tasks/image-to-image/about.md +129 -0
  78. package/src/tasks/image-to-image/data.ts +101 -0
  79. package/src/tasks/image-to-image/inference.ts +68 -0
  80. package/src/tasks/image-to-image/spec/input.json +55 -0
  81. package/src/tasks/image-to-image/spec/output.json +12 -0
  82. package/src/tasks/image-to-text/about.md +61 -0
  83. package/src/tasks/image-to-text/data.ts +82 -0
  84. package/src/tasks/image-to-text/inference.ts +143 -0
  85. package/src/tasks/image-to-text/spec/input.json +34 -0
  86. package/src/tasks/image-to-text/spec/output.json +14 -0
  87. package/src/tasks/index.ts +312 -0
  88. package/src/tasks/keypoint-detection/about.md +57 -0
  89. package/src/tasks/keypoint-detection/data.ts +50 -0
  90. package/src/tasks/mask-generation/about.md +65 -0
  91. package/src/tasks/mask-generation/data.ts +55 -0
  92. package/src/tasks/object-detection/about.md +37 -0
  93. package/src/tasks/object-detection/data.ts +86 -0
  94. package/src/tasks/object-detection/inference.ts +75 -0
  95. package/src/tasks/object-detection/spec/input.json +31 -0
  96. package/src/tasks/object-detection/spec/output.json +50 -0
  97. package/src/tasks/placeholder/about.md +15 -0
  98. package/src/tasks/placeholder/data.ts +21 -0
  99. package/src/tasks/placeholder/spec/input.json +35 -0
  100. package/src/tasks/placeholder/spec/output.json +17 -0
  101. package/src/tasks/question-answering/about.md +56 -0
  102. package/src/tasks/question-answering/data.ts +75 -0
  103. package/src/tasks/question-answering/inference.ts +99 -0
  104. package/src/tasks/question-answering/spec/input.json +67 -0
  105. package/src/tasks/question-answering/spec/output.json +29 -0
  106. package/src/tasks/reinforcement-learning/about.md +167 -0
  107. package/src/tasks/reinforcement-learning/data.ts +75 -0
  108. package/src/tasks/sentence-similarity/about.md +97 -0
  109. package/src/tasks/sentence-similarity/data.ts +101 -0
  110. package/src/tasks/sentence-similarity/inference.ts +32 -0
  111. package/src/tasks/sentence-similarity/spec/input.json +40 -0
  112. package/src/tasks/sentence-similarity/spec/output.json +12 -0
  113. package/src/tasks/summarization/about.md +58 -0
  114. package/src/tasks/summarization/data.ts +76 -0
  115. package/src/tasks/summarization/inference.ts +57 -0
  116. package/src/tasks/summarization/spec/input.json +42 -0
  117. package/src/tasks/summarization/spec/output.json +14 -0
  118. package/src/tasks/table-question-answering/about.md +43 -0
  119. package/src/tasks/table-question-answering/data.ts +59 -0
  120. package/src/tasks/table-question-answering/inference.ts +61 -0
  121. package/src/tasks/table-question-answering/spec/input.json +44 -0
  122. package/src/tasks/table-question-answering/spec/output.json +40 -0
  123. package/src/tasks/tabular-classification/about.md +65 -0
  124. package/src/tasks/tabular-classification/data.ts +68 -0
  125. package/src/tasks/tabular-regression/about.md +87 -0
  126. package/src/tasks/tabular-regression/data.ts +57 -0
  127. package/src/tasks/text-classification/about.md +173 -0
  128. package/src/tasks/text-classification/data.ts +103 -0
  129. package/src/tasks/text-classification/inference.ts +51 -0
  130. package/src/tasks/text-classification/spec/input.json +35 -0
  131. package/src/tasks/text-classification/spec/output.json +11 -0
  132. package/src/tasks/text-generation/about.md +154 -0
  133. package/src/tasks/text-generation/data.ts +114 -0
  134. package/src/tasks/text-generation/inference.ts +200 -0
  135. package/src/tasks/text-generation/spec/input.json +219 -0
  136. package/src/tasks/text-generation/spec/output.json +179 -0
  137. package/src/tasks/text-generation/spec/stream_output.json +103 -0
  138. package/src/tasks/text-to-3d/about.md +62 -0
  139. package/src/tasks/text-to-3d/data.ts +56 -0
  140. package/src/tasks/text-to-audio/inference.ts +143 -0
  141. package/src/tasks/text-to-audio/spec/input.json +31 -0
  142. package/src/tasks/text-to-audio/spec/output.json +17 -0
  143. package/src/tasks/text-to-image/about.md +96 -0
  144. package/src/tasks/text-to-image/data.ts +100 -0
  145. package/src/tasks/text-to-image/inference.ts +75 -0
  146. package/src/tasks/text-to-image/spec/input.json +63 -0
  147. package/src/tasks/text-to-image/spec/output.json +13 -0
  148. package/src/tasks/text-to-speech/about.md +63 -0
  149. package/src/tasks/text-to-speech/data.ts +79 -0
  150. package/src/tasks/text-to-speech/inference.ts +145 -0
  151. package/src/tasks/text-to-speech/spec/input.json +31 -0
  152. package/src/tasks/text-to-speech/spec/output.json +7 -0
  153. package/src/tasks/text-to-video/about.md +41 -0
  154. package/src/tasks/text-to-video/data.ts +102 -0
  155. package/src/tasks/text2text-generation/inference.ts +55 -0
  156. package/src/tasks/text2text-generation/spec/input.json +55 -0
  157. package/src/tasks/text2text-generation/spec/output.json +14 -0
  158. package/src/tasks/token-classification/about.md +76 -0
  159. package/src/tasks/token-classification/data.ts +92 -0
  160. package/src/tasks/token-classification/inference.ts +85 -0
  161. package/src/tasks/token-classification/spec/input.json +65 -0
  162. package/src/tasks/token-classification/spec/output.json +37 -0
  163. package/src/tasks/translation/about.md +65 -0
  164. package/src/tasks/translation/data.ts +70 -0
  165. package/src/tasks/translation/inference.ts +67 -0
  166. package/src/tasks/translation/spec/input.json +50 -0
  167. package/src/tasks/translation/spec/output.json +14 -0
  168. package/src/tasks/unconditional-image-generation/about.md +50 -0
  169. package/src/tasks/unconditional-image-generation/data.ts +72 -0
  170. package/src/tasks/video-classification/about.md +37 -0
  171. package/src/tasks/video-classification/data.ts +84 -0
  172. package/src/tasks/video-classification/inference.ts +59 -0
  173. package/src/tasks/video-classification/spec/input.json +42 -0
  174. package/src/tasks/video-classification/spec/output.json +10 -0
  175. package/src/tasks/video-text-to-text/about.md +98 -0
  176. package/src/tasks/video-text-to-text/data.ts +66 -0
  177. package/src/tasks/visual-question-answering/about.md +48 -0
  178. package/src/tasks/visual-question-answering/data.ts +97 -0
  179. package/src/tasks/visual-question-answering/inference.ts +62 -0
  180. package/src/tasks/visual-question-answering/spec/input.json +41 -0
  181. package/src/tasks/visual-question-answering/spec/output.json +21 -0
  182. package/src/tasks/zero-shot-classification/about.md +40 -0
  183. package/src/tasks/zero-shot-classification/data.ts +70 -0
  184. package/src/tasks/zero-shot-classification/inference.ts +67 -0
  185. package/src/tasks/zero-shot-classification/spec/input.json +50 -0
  186. package/src/tasks/zero-shot-classification/spec/output.json +11 -0
  187. package/src/tasks/zero-shot-image-classification/about.md +75 -0
  188. package/src/tasks/zero-shot-image-classification/data.ts +84 -0
  189. package/src/tasks/zero-shot-image-classification/inference.ts +61 -0
  190. package/src/tasks/zero-shot-image-classification/spec/input.json +45 -0
  191. package/src/tasks/zero-shot-image-classification/spec/output.json +10 -0
  192. package/src/tasks/zero-shot-object-detection/about.md +45 -0
  193. package/src/tasks/zero-shot-object-detection/data.ts +67 -0
  194. package/src/tasks/zero-shot-object-detection/inference.ts +66 -0
  195. package/src/tasks/zero-shot-object-detection/spec/input.json +40 -0
  196. package/src/tasks/zero-shot-object-detection/spec/output.json +47 -0
  197. package/src/tokenizer-data.ts +32 -0
  198. package/src/widget-example.ts +125 -0
@@ -0,0 +1,51 @@
1
+ ## Use Cases
2
+
3
+ ### Domain Adaptation 👩‍⚕️
4
+
5
+ Masked language models do not require labelled data! They are trained by masking a couple of words in sentences and the model is expected to guess the masked word. This makes it very practical!
6
+
7
+ For example, masked language modeling is used to train large models for domain-specific problems. If you have to work on a domain-specific task, such as retrieving information from medical research papers, you can train a masked language model using those papers. 📄
8
+
9
+ The resulting model has a statistical understanding of the language used in medical research papers, and can be further trained in a process called fine-tuning to solve different tasks, such as [Text Classification](/tasks/text-classification) or [Question Answering](/tasks/question-answering) to build a medical research papers information extraction system. 👩‍⚕️ Pre-training on domain-specific data tends to yield better results (see [this paper](https://arxiv.org/abs/2007.15779) for an example).
10
+
11
+ If you don't have the data to train a masked language model, you can also use an existing [domain-specific masked language model](https://huggingface.co/microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext) from the Hub and fine-tune it with your smaller task dataset. That's the magic of Open Source and sharing your work! 🎉
12
+
13
+ ## Inference with Fill-Mask Pipeline
14
+
15
+ You can use the 🤗 Transformers library `fill-mask` pipeline to do inference with masked language models. If a model name is not provided, the pipeline will be initialized with [distilroberta-base](/distilroberta-base). You can provide masked text and it will return a list of possible mask values ​​ranked according to the score.
16
+
17
+ ```python
18
+ from transformers import pipeline
19
+
20
+ classifier = pipeline("fill-mask")
21
+ classifier("Paris is the <mask> of France.")
22
+
23
+ # [{'score': 0.7, 'sequence': 'Paris is the capital of France.'},
24
+ # {'score': 0.2, 'sequence': 'Paris is the birthplace of France.'},
25
+ # {'score': 0.1, 'sequence': 'Paris is the heart of France.'}]
26
+ ```
27
+
28
+ ## Useful Resources
29
+
30
+ Would you like to learn more about the topic? Awesome! Here you can find some curated resources that can be helpful to you!
31
+
32
+ - [Course Chapter on Fine-tuning a Masked Language Model](https://huggingface.co/course/chapter7/3?fw=pt)
33
+ - [Workshop on Pretraining Language Models and CodeParrot](https://www.youtube.com/watch?v=ExUR7w6xe94)
34
+ - [BERT 101: State Of The Art NLP Model Explained](https://huggingface.co/blog/bert-101)
35
+ - [Nyströmformer: Approximating self-attention in linear time and memory via the Nyström method](https://huggingface.co/blog/nystromformer)
36
+
37
+ ### Notebooks
38
+
39
+ - [Pre-training an MLM for JAX/Flax](https://github.com/huggingface/notebooks/blob/master/examples/masked_language_modeling_flax.ipynb)
40
+ - [Masked language modeling in TensorFlow](https://github.com/huggingface/notebooks/blob/master/examples/language_modeling-tf.ipynb)
41
+ - [Masked language modeling in PyTorch](https://github.com/huggingface/notebooks/blob/master/examples/language_modeling.ipynb)
42
+
43
+ ### Scripts for training
44
+
45
+ - [PyTorch](https://github.com/huggingface/transformers/tree/main/examples/pytorch/language-modeling)
46
+ - [Flax](https://github.com/huggingface/transformers/tree/main/examples/flax/language-modeling)
47
+ - [TensorFlow](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/language-modeling)
48
+
49
+ ### Documentation
50
+
51
+ - [Masked language modeling task guide](https://huggingface.co/docs/transformers/tasks/masked_language_modeling)
@@ -0,0 +1,79 @@
1
+ import type { TaskDataCustom } from "../index.js";
2
+
3
+ const taskData: TaskDataCustom = {
4
+ datasets: [
5
+ {
6
+ description: "A common dataset that is used to train models for many languages.",
7
+ id: "wikipedia",
8
+ },
9
+ {
10
+ description: "A large English dataset with text crawled from the web.",
11
+ id: "c4",
12
+ },
13
+ ],
14
+ demo: {
15
+ inputs: [
16
+ {
17
+ label: "Input",
18
+ content: "The <mask> barked at me",
19
+ type: "text",
20
+ },
21
+ ],
22
+ outputs: [
23
+ {
24
+ type: "chart",
25
+ data: [
26
+ {
27
+ label: "wolf",
28
+ score: 0.487,
29
+ },
30
+ {
31
+ label: "dog",
32
+ score: 0.061,
33
+ },
34
+ {
35
+ label: "cat",
36
+ score: 0.058,
37
+ },
38
+ {
39
+ label: "fox",
40
+ score: 0.047,
41
+ },
42
+ {
43
+ label: "squirrel",
44
+ score: 0.025,
45
+ },
46
+ ],
47
+ },
48
+ ],
49
+ },
50
+ metrics: [
51
+ {
52
+ description:
53
+ "Cross Entropy is a metric that calculates the difference between two probability distributions. Each probability distribution is the distribution of predicted words",
54
+ id: "cross_entropy",
55
+ },
56
+ {
57
+ description:
58
+ "Perplexity is the exponential of the cross-entropy loss. It evaluates the probabilities assigned to the next word by the model. Lower perplexity indicates better performance",
59
+ id: "perplexity",
60
+ },
61
+ ],
62
+ models: [
63
+ {
64
+ description: "The famous BERT model.",
65
+ id: "google-bert/bert-base-uncased",
66
+ },
67
+ {
68
+ description: "A multilingual model trained on 100 languages.",
69
+ id: "FacebookAI/xlm-roberta-base",
70
+ },
71
+ ],
72
+ spaces: [],
73
+ summary:
74
+ "Masked language modeling is the task of masking some of the words in a sentence and predicting which words should replace those masks. These models are useful when we want to get a statistical understanding of the language in which the model is trained in.",
75
+ widgetModels: ["distilroberta-base"],
76
+ youtubeId: "mqElG5QJWUg",
77
+ };
78
+
79
+ export default taskData;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Inference code generated from the JSON schema spec in ./spec
3
+ *
4
+ * Using src/scripts/inference-codegen
5
+ */
6
+ /**
7
+ * Inputs for Fill Mask inference
8
+ */
9
+ export interface FillMaskInput {
10
+ /**
11
+ * The text with masked tokens
12
+ */
13
+ inputs: string;
14
+ /**
15
+ * Additional inference parameters
16
+ */
17
+ parameters?: FillMaskParameters;
18
+ [property: string]: unknown;
19
+ }
20
+ /**
21
+ * Additional inference parameters
22
+ *
23
+ * Additional inference parameters for Fill Mask
24
+ */
25
+ export interface FillMaskParameters {
26
+ /**
27
+ * When passed, the model will limit the scores to the passed targets instead of looking up
28
+ * in the whole vocabulary. If the provided targets are not in the model vocab, they will be
29
+ * tokenized and the first resulting token will be used (with a warning, and that might be
30
+ * slower).
31
+ */
32
+ targets?: string[];
33
+ /**
34
+ * When passed, overrides the number of predictions to return.
35
+ */
36
+ top_k?: number;
37
+ [property: string]: unknown;
38
+ }
39
+ export type FillMaskOutput = FillMaskOutputElement[];
40
+ /**
41
+ * Outputs of inference for the Fill Mask task
42
+ */
43
+ export interface FillMaskOutputElement {
44
+ /**
45
+ * The corresponding probability
46
+ */
47
+ score: number;
48
+ /**
49
+ * The corresponding input with the mask token prediction.
50
+ */
51
+ sequence: string;
52
+ /**
53
+ * The predicted token id (to replace the masked one).
54
+ */
55
+ token: number;
56
+ tokenStr: unknown;
57
+ /**
58
+ * The predicted token (to replace the masked one).
59
+ */
60
+ token_str?: string;
61
+ [property: string]: unknown;
62
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "$id": "/inference/schemas/fill-mask/input.json",
3
+ "$schema": "http://json-schema.org/draft-06/schema#",
4
+ "description": "Inputs for Fill Mask inference",
5
+ "title": "FillMaskInput",
6
+ "type": "object",
7
+ "properties": {
8
+ "inputs": {
9
+ "description": "The text with masked tokens",
10
+ "type": "string"
11
+ },
12
+ "parameters": {
13
+ "description": "Additional inference parameters",
14
+ "$ref": "#/$defs/FillMaskParameters"
15
+ }
16
+ },
17
+ "$defs": {
18
+ "FillMaskParameters": {
19
+ "title": "FillMaskParameters",
20
+ "description": "Additional inference parameters for Fill Mask",
21
+ "type": "object",
22
+ "properties": {
23
+ "top_k": {
24
+ "type": "integer",
25
+ "description": "When passed, overrides the number of predictions to return."
26
+ },
27
+ "targets": {
28
+ "description": "When passed, the model will limit the scores to the passed targets instead of looking up in the whole vocabulary. If the provided targets are not in the model vocab, they will be tokenized and the first resulting token will be used (with a warning, and that might be slower).",
29
+ "type": "array",
30
+ "items": {
31
+ "type": "string"
32
+ }
33
+ }
34
+ }
35
+ }
36
+ },
37
+ "required": ["inputs"]
38
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "$id": "/inference/schemas/fill-mask/output.json",
3
+ "$schema": "http://json-schema.org/draft-06/schema#",
4
+ "description": "Outputs of inference for the Fill Mask task",
5
+ "title": "FillMaskOutput",
6
+ "type": "array",
7
+ "items": {
8
+ "type": "object",
9
+ "properties": {
10
+ "sequence": {
11
+ "type": "string",
12
+ "description": "The corresponding input with the mask token prediction."
13
+ },
14
+ "score": {
15
+ "type": "number",
16
+ "description": "The corresponding probability"
17
+ },
18
+ "token": {
19
+ "type": "integer",
20
+ "description": "The predicted token id (to replace the masked one)."
21
+ },
22
+ "token_str": {
23
+ "type": "string",
24
+ "description": "The predicted token (to replace the masked one)."
25
+ }
26
+ },
27
+ "required": ["sequence", "score", "token", "tokenStr"]
28
+ }
29
+ }
@@ -0,0 +1,50 @@
1
+ ## Use Cases
2
+
3
+ Image classification models can be used when we are not interested in specific instances of objects with location information or their shape.
4
+
5
+ ### Keyword Classification
6
+
7
+ Image classification models are used widely in stock photography to assign each image a keyword.
8
+
9
+ ### Image Search
10
+
11
+ Models trained in image classification can improve user experience by organizing and categorizing photo galleries on the phone or in the cloud, on multiple keywords or tags.
12
+
13
+ ## Inference
14
+
15
+ With the `transformers` library, you can use the `image-classification` pipeline to infer with image classification models. You can initialize the pipeline with a model id from the Hub. If you do not provide a model id it will initialize with [google/vit-base-patch16-224](https://huggingface.co/google/vit-base-patch16-224) by default. When calling the pipeline you just need to specify a path, http link or an image loaded in PIL. You can also provide a `top_k` parameter which determines how many results it should return.
16
+
17
+ ```python
18
+ from transformers import pipeline
19
+ clf = pipeline("image-classification")
20
+ clf("path_to_a_cat_image")
21
+
22
+ [{'label': 'tabby cat', 'score': 0.731},
23
+ ...
24
+ ]
25
+ ```
26
+
27
+ You can use [huggingface.js](https://github.com/huggingface/huggingface.js) to classify images using models on Hugging Face Hub.
28
+
29
+ ```javascript
30
+ import { HfInference } from "@huggingface/inference";
31
+
32
+ const inference = new HfInference(HF_TOKEN);
33
+ await inference.imageClassification({
34
+ data: await (await fetch("https://picsum.photos/300/300")).blob(),
35
+ model: "microsoft/resnet-50",
36
+ });
37
+ ```
38
+
39
+ ## Useful Resources
40
+
41
+ - [Let's Play Pictionary with Machine Learning!](https://www.youtube.com/watch?v=LS9Y2wDVI0k)
42
+ - [Fine-Tune ViT for Image Classification with 🤗Transformers](https://huggingface.co/blog/fine-tune-vit)
43
+ - [Walkthrough of Computer Vision Ecosystem in Hugging Face - CV Study Group](https://www.youtube.com/watch?v=oL-xmufhZM8)
44
+ - [Computer Vision Study Group: Swin Transformer](https://www.youtube.com/watch?v=Ngikt-K1Ecc)
45
+ - [Computer Vision Study Group: Masked Autoencoders Paper Walkthrough](https://www.youtube.com/watch?v=Ngikt-K1Ecc)
46
+ - [Image classification task guide](https://huggingface.co/docs/transformers/tasks/image_classification)
47
+
48
+ ### Creating your own image classifier in just a few minutes
49
+
50
+ With [HuggingPics](https://github.com/nateraw/huggingpics), you can fine-tune Vision Transformers for anything using images found on the web. This project downloads images of classes defined by you, trains a model, and pushes it to the Hub. You even get to try out the model directly with a working widget in the browser, ready to be shared with all your friends!
@@ -0,0 +1,88 @@
1
+ import type { TaskDataCustom } from "../index.js";
2
+
3
+ const taskData: TaskDataCustom = {
4
+ datasets: [
5
+ {
6
+ // TODO write proper description
7
+ description: "Benchmark dataset used for image classification with images that belong to 100 classes.",
8
+ id: "cifar100",
9
+ },
10
+ {
11
+ // TODO write proper description
12
+ description: "Dataset consisting of images of garments.",
13
+ id: "fashion_mnist",
14
+ },
15
+ ],
16
+ demo: {
17
+ inputs: [
18
+ {
19
+ filename: "image-classification-input.jpeg",
20
+ type: "img",
21
+ },
22
+ ],
23
+ outputs: [
24
+ {
25
+ type: "chart",
26
+ data: [
27
+ {
28
+ label: "Egyptian cat",
29
+ score: 0.514,
30
+ },
31
+ {
32
+ label: "Tabby cat",
33
+ score: 0.193,
34
+ },
35
+ {
36
+ label: "Tiger cat",
37
+ score: 0.068,
38
+ },
39
+ ],
40
+ },
41
+ ],
42
+ },
43
+ metrics: [
44
+ {
45
+ description: "",
46
+ id: "accuracy",
47
+ },
48
+ {
49
+ description: "",
50
+ id: "recall",
51
+ },
52
+ {
53
+ description: "",
54
+ id: "precision",
55
+ },
56
+ {
57
+ description: "",
58
+ id: "f1",
59
+ },
60
+ ],
61
+ models: [
62
+ {
63
+ description: "A strong image classification model.",
64
+ id: "google/vit-base-patch16-224",
65
+ },
66
+ {
67
+ description: "A robust image classification model.",
68
+ id: "facebook/deit-base-distilled-patch16-224",
69
+ },
70
+ {
71
+ description: "A strong image classification model.",
72
+ id: "facebook/convnext-large-224",
73
+ },
74
+ ],
75
+ spaces: [
76
+ {
77
+ // TO DO: write description
78
+ description: "An application that classifies what a given image is about.",
79
+ id: "nielsr/perceiver-image-classification",
80
+ },
81
+ ],
82
+ summary:
83
+ "Image classification is the task of assigning a label or class to an entire image. Images are expected to have only one class for each image. Image classification models take an image as input and return a prediction about which class the image belongs to.",
84
+ widgetModels: ["google/vit-base-patch16-224"],
85
+ youtubeId: "tjAIM7BOYhw",
86
+ };
87
+
88
+ export default taskData;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Inference code generated from the JSON schema spec in ./spec
3
+ *
4
+ * Using src/scripts/inference-codegen
5
+ */
6
+ /**
7
+ * Inputs for Image Classification inference
8
+ */
9
+ export interface ImageClassificationInput {
10
+ /**
11
+ * The input image data as a base64-encoded string. If no `parameters` are provided, you can
12
+ * also provide the image data as a raw bytes payload.
13
+ */
14
+ inputs: string;
15
+ /**
16
+ * Additional inference parameters
17
+ */
18
+ parameters?: ImageClassificationParameters;
19
+ [property: string]: unknown;
20
+ }
21
+ /**
22
+ * Additional inference parameters
23
+ *
24
+ * Additional inference parameters for Image Classification
25
+ */
26
+ export interface ImageClassificationParameters {
27
+ function_to_apply?: ClassificationOutputTransform;
28
+ /**
29
+ * When specified, limits the output to the top K most probable classes.
30
+ */
31
+ top_k?: number;
32
+ [property: string]: unknown;
33
+ }
34
+ /**
35
+ * The function to apply to the model outputs in order to retrieve the scores.
36
+ */
37
+ export type ClassificationOutputTransform = "sigmoid" | "softmax" | "none";
38
+ export type ImageClassificationOutput = ImageClassificationOutputElement[];
39
+ /**
40
+ * Outputs of inference for the Image Classification task
41
+ */
42
+ export interface ImageClassificationOutputElement {
43
+ /**
44
+ * The predicted class label.
45
+ */
46
+ label: string;
47
+ /**
48
+ * The corresponding probability.
49
+ */
50
+ score: number;
51
+ [property: string]: unknown;
52
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "$id": "/inference/schemas/image-classification/input.json",
3
+ "$schema": "http://json-schema.org/draft-06/schema#",
4
+ "description": "Inputs for Image Classification inference",
5
+ "title": "ImageClassificationInput",
6
+ "type": "object",
7
+ "properties": {
8
+ "inputs": {
9
+ "type": "string",
10
+ "description": "The input image data as a base64-encoded string. If no `parameters` are provided, you can also provide the image data as a raw bytes payload."
11
+ },
12
+ "parameters": {
13
+ "description": "Additional inference parameters",
14
+ "$ref": "#/$defs/ImageClassificationParameters"
15
+ }
16
+ },
17
+ "$defs": {
18
+ "ImageClassificationParameters": {
19
+ "title": "ImageClassificationParameters",
20
+ "description": "Additional inference parameters for Image Classification",
21
+ "type": "object",
22
+ "properties": {
23
+ "function_to_apply": {
24
+ "title": "ImageClassificationOutputTransform",
25
+ "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutputTransform"
26
+ },
27
+ "top_k": {
28
+ "type": "integer",
29
+ "description": "When specified, limits the output to the top K most probable classes."
30
+ }
31
+ }
32
+ }
33
+ },
34
+ "required": ["inputs"]
35
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$id": "/inference/schemas/image-classification/output.json",
3
+ "$schema": "http://json-schema.org/draft-06/schema#",
4
+ "description": "Outputs of inference for the Image Classification task",
5
+ "title": "ImageClassificationOutput",
6
+ "type": "array",
7
+ "items": {
8
+ "type": "object",
9
+ "$ref": "/inference/schemas/common-definitions.json#/definitions/ClassificationOutput"
10
+ }
11
+ }
@@ -0,0 +1,23 @@
1
+ ## Use Cases
2
+
3
+ ### Transfer Learning
4
+
5
+ Models trained on a specific dataset can learn features about the data. For instance, a model trained on a car classification dataset learns to recognize edges and curves on a very high level and car-specific features on a low level. This information can be transferred to a new model that is going to be trained on classifying trucks. This process of extracting features and transferring to another model is called transfer learning.
6
+
7
+ ### Similarity
8
+
9
+ Features extracted from models contain semantically meaningful information about the world. These features can be used to detect the similarity between two images. Assume there are two images: a photo of a stray cat in a street setting and a photo of a cat at home. These images both contain cats, and the features will contain the information that there's a cat in the image. Thus, comparing the features of a stray cat photo to the features of a domestic cat photo will result in higher similarity compared to any other image that doesn't contain any cats.
10
+
11
+ ## Inference
12
+
13
+ ```python
14
+ import torch
15
+ from transformers import pipeline
16
+
17
+ pipe = pipeline(task="image-feature-extraction", model_name="google/vit-base-patch16-384", framework="pt", pool=True)
18
+ pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/cats.png")
19
+
20
+ feature_extractor(text,return_tensors = "pt")[0].numpy().mean(axis=0)
21
+
22
+ '[[[0.21236686408519745, 1.0919708013534546, 0.8512550592422485, ...]]]'
23
+ ```
@@ -0,0 +1,59 @@
1
+ import type { TaskDataCustom } from "../index.js";
2
+
3
+ const taskData: TaskDataCustom = {
4
+ datasets: [
5
+ {
6
+ description:
7
+ "ImageNet-1K is a image classification dataset in which images are used to train image-feature-extraction models.",
8
+ id: "imagenet-1k",
9
+ },
10
+ ],
11
+ demo: {
12
+ inputs: [
13
+ {
14
+ filename: "mask-generation-input.png",
15
+ type: "img",
16
+ },
17
+ ],
18
+ outputs: [
19
+ {
20
+ table: [
21
+ ["Dimension 1", "Dimension 2", "Dimension 3"],
22
+ ["0.21236686408519745", "1.0919708013534546", "0.8512550592422485"],
23
+ ["0.809657871723175", "-0.18544459342956543", "-0.7851548194885254"],
24
+ ["1.3103108406066895", "-0.2479034662246704", "-0.9107287526130676"],
25
+ ["1.8536205291748047", "-0.36419737339019775", "0.09717650711536407"],
26
+ ],
27
+ type: "tabular",
28
+ },
29
+ ],
30
+ },
31
+ metrics: [],
32
+ models: [
33
+ {
34
+ description: "A powerful image feature extraction model.",
35
+ id: "timm/vit_large_patch14_dinov2.lvd142m",
36
+ },
37
+ {
38
+ description: "A strong image feature extraction model.",
39
+ id: "nvidia/MambaVision-T-1K",
40
+ },
41
+ {
42
+ description: "A robust image feature extraction model.",
43
+ id: "facebook/dino-vitb16",
44
+ },
45
+ {
46
+ description: "Strong image feature extraction model made for information retrieval from documents.",
47
+ id: "vidore/colpali",
48
+ },
49
+ {
50
+ description: "Strong image feature extraction model that can be used on images and documents.",
51
+ id: "OpenGVLab/InternViT-6B-448px-V1-2",
52
+ },
53
+ ],
54
+ spaces: [],
55
+ summary: "Image feature extraction is the task of extracting features learnt in a computer vision model.",
56
+ widgetModels: [],
57
+ };
58
+
59
+ export default taskData;
@@ -0,0 +1,63 @@
1
+ ## Use Cases
2
+
3
+ ### Autonomous Driving
4
+
5
+ Segmentation models are used to identify road patterns such as lanes and obstacles for safer driving.
6
+
7
+ ### Background Removal
8
+
9
+ Image Segmentation models are used in cameras to erase the background of certain objects and apply filters to them.
10
+
11
+ ### Medical Imaging
12
+
13
+ Image Segmentation models are used to distinguish organs or tissues, improving medical imaging workflows. Models are used to segment dental instances, analyze X-Ray scans or even segment cells for pathological diagnosis. This [dataset](https://github.com/v7labs/covid-19-xray-dataset) contains images of lungs of healthy patients and patients with COVID-19 segmented with masks. Another [segmentation dataset](https://ivdm3seg.weebly.com/data.html) contains segmented MRI data of the lower spine to analyze the effect of spaceflight simulation.
14
+
15
+ ## Task Variants
16
+
17
+ ### Semantic Segmentation
18
+
19
+ Semantic Segmentation is the task of segmenting parts of an image that belong to the same class. Semantic Segmentation models make predictions for each pixel and return the probabilities of the classes for each pixel. These models are evaluated on Mean Intersection Over Union (Mean IoU).
20
+
21
+ ### Instance Segmentation
22
+
23
+ Instance Segmentation is the variant of Image Segmentation where every distinct object is segmented, instead of one segment per class.
24
+
25
+ ### Panoptic Segmentation
26
+
27
+ Panoptic Segmentation is the Image Segmentation task that segments the image both by instance and by class, assigning each pixel a different instance of the class.
28
+
29
+ ## Inference
30
+
31
+ You can infer with Image Segmentation models using the `image-segmentation` pipeline. You need to install [timm](https://github.com/rwightman/pytorch-image-models) first.
32
+
33
+ ```python
34
+ !pip install timm
35
+ model = pipeline("image-segmentation")
36
+ model("cat.png")
37
+ #[{'label': 'cat',
38
+ # 'mask': mask_code,
39
+ # 'score': 0.999}
40
+ # ...]
41
+ ```
42
+
43
+ You can use [huggingface.js](https://github.com/huggingface/huggingface.js) to infer image segmentation models on Hugging Face Hub.
44
+
45
+ ```javascript
46
+ import { HfInference } from "@huggingface/inference";
47
+
48
+ const inference = new HfInference(HF_TOKEN);
49
+ await inference.imageSegmentation({
50
+ data: await (await fetch("https://picsum.photos/300/300")).blob(),
51
+ model: "facebook/mask2former-swin-base-coco-panoptic",
52
+ });
53
+ ```
54
+
55
+ ## Useful Resources
56
+
57
+ Would you like to learn more about image segmentation? Great! Here you can find some curated resources that you may find helpful!
58
+
59
+ - [Fine-Tune a Semantic Segmentation Model with a Custom Dataset](https://huggingface.co/blog/fine-tune-segformer)
60
+ - [Walkthrough of Computer Vision Ecosystem in Hugging Face - CV Study Group](https://www.youtube.com/watch?v=oL-xmufhZM8)
61
+ - [A Guide on Universal Image Segmentation with Mask2Former and OneFormer](https://huggingface.co/blog/mask2former)
62
+ - [Zero-shot image segmentation with CLIPSeg](https://huggingface.co/blog/clipseg-zero-shot)
63
+ - [Semantic segmentation task guide](https://huggingface.co/docs/transformers/tasks/semantic_segmentation)