@huggingface/tasks 0.0.1

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 (103) hide show
  1. package/assets/audio-classification/audio.wav +0 -0
  2. package/assets/audio-to-audio/input.wav +0 -0
  3. package/assets/audio-to-audio/label-0.wav +0 -0
  4. package/assets/audio-to-audio/label-1.wav +0 -0
  5. package/assets/automatic-speech-recognition/input.flac +0 -0
  6. package/assets/automatic-speech-recognition/wav2vec2.png +0 -0
  7. package/assets/contribution-guide/anatomy.png +0 -0
  8. package/assets/contribution-guide/libraries.png +0 -0
  9. package/assets/depth-estimation/depth-estimation-input.jpg +0 -0
  10. package/assets/depth-estimation/depth-estimation-output.png +0 -0
  11. package/assets/document-question-answering/document-question-answering-input.png +0 -0
  12. package/assets/image-classification/image-classification-input.jpeg +0 -0
  13. package/assets/image-segmentation/image-segmentation-input.jpeg +0 -0
  14. package/assets/image-segmentation/image-segmentation-output.png +0 -0
  15. package/assets/image-to-image/image-to-image-input.jpeg +0 -0
  16. package/assets/image-to-image/image-to-image-output.png +0 -0
  17. package/assets/image-to-image/pix2pix_examples.jpg +0 -0
  18. package/assets/image-to-text/savanna.jpg +0 -0
  19. package/assets/object-detection/object-detection-input.jpg +0 -0
  20. package/assets/object-detection/object-detection-output.jpg +0 -0
  21. package/assets/table-question-answering/tableQA.jpg +0 -0
  22. package/assets/text-to-image/image.jpeg +0 -0
  23. package/assets/text-to-speech/audio.wav +0 -0
  24. package/assets/text-to-video/text-to-video-output.gif +0 -0
  25. package/assets/unconditional-image-generation/unconditional-image-generation-output.jpeg +0 -0
  26. package/assets/video-classification/video-classification-input.gif +0 -0
  27. package/assets/visual-question-answering/elephant.jpeg +0 -0
  28. package/assets/zero-shot-image-classification/image-classification-input.jpeg +0 -0
  29. package/dist/index.cjs +3105 -0
  30. package/dist/index.d.cts +145 -0
  31. package/dist/index.d.ts +145 -0
  32. package/dist/index.js +3079 -0
  33. package/package.json +35 -0
  34. package/src/Types.ts +58 -0
  35. package/src/audio-classification/about.md +85 -0
  36. package/src/audio-classification/data.ts +77 -0
  37. package/src/audio-to-audio/about.md +55 -0
  38. package/src/audio-to-audio/data.ts +63 -0
  39. package/src/automatic-speech-recognition/about.md +86 -0
  40. package/src/automatic-speech-recognition/data.ts +77 -0
  41. package/src/const.ts +51 -0
  42. package/src/conversational/about.md +50 -0
  43. package/src/conversational/data.ts +62 -0
  44. package/src/depth-estimation/about.md +38 -0
  45. package/src/depth-estimation/data.ts +52 -0
  46. package/src/document-question-answering/about.md +54 -0
  47. package/src/document-question-answering/data.ts +67 -0
  48. package/src/feature-extraction/about.md +35 -0
  49. package/src/feature-extraction/data.ts +57 -0
  50. package/src/fill-mask/about.md +51 -0
  51. package/src/fill-mask/data.ts +77 -0
  52. package/src/image-classification/about.md +48 -0
  53. package/src/image-classification/data.ts +88 -0
  54. package/src/image-segmentation/about.md +63 -0
  55. package/src/image-segmentation/data.ts +96 -0
  56. package/src/image-to-image/about.md +81 -0
  57. package/src/image-to-image/data.ts +97 -0
  58. package/src/image-to-text/about.md +58 -0
  59. package/src/image-to-text/data.ts +87 -0
  60. package/src/index.ts +2 -0
  61. package/src/object-detection/about.md +36 -0
  62. package/src/object-detection/data.ts +73 -0
  63. package/src/placeholder/about.md +15 -0
  64. package/src/placeholder/data.ts +18 -0
  65. package/src/question-answering/about.md +56 -0
  66. package/src/question-answering/data.ts +69 -0
  67. package/src/reinforcement-learning/about.md +176 -0
  68. package/src/reinforcement-learning/data.ts +78 -0
  69. package/src/sentence-similarity/about.md +97 -0
  70. package/src/sentence-similarity/data.ts +100 -0
  71. package/src/summarization/about.md +57 -0
  72. package/src/summarization/data.ts +72 -0
  73. package/src/table-question-answering/about.md +43 -0
  74. package/src/table-question-answering/data.ts +63 -0
  75. package/src/tabular-classification/about.md +67 -0
  76. package/src/tabular-classification/data.ts +69 -0
  77. package/src/tabular-regression/about.md +91 -0
  78. package/src/tabular-regression/data.ts +58 -0
  79. package/src/tasksData.ts +104 -0
  80. package/src/text-classification/about.md +171 -0
  81. package/src/text-classification/data.ts +90 -0
  82. package/src/text-generation/about.md +128 -0
  83. package/src/text-generation/data.ts +124 -0
  84. package/src/text-to-image/about.md +65 -0
  85. package/src/text-to-image/data.ts +88 -0
  86. package/src/text-to-speech/about.md +63 -0
  87. package/src/text-to-speech/data.ts +70 -0
  88. package/src/text-to-video/about.md +36 -0
  89. package/src/text-to-video/data.ts +97 -0
  90. package/src/token-classification/about.md +78 -0
  91. package/src/token-classification/data.ts +83 -0
  92. package/src/translation/about.md +65 -0
  93. package/src/translation/data.ts +68 -0
  94. package/src/unconditional-image-generation/about.md +45 -0
  95. package/src/unconditional-image-generation/data.ts +66 -0
  96. package/src/video-classification/about.md +53 -0
  97. package/src/video-classification/data.ts +84 -0
  98. package/src/visual-question-answering/about.md +43 -0
  99. package/src/visual-question-answering/data.ts +90 -0
  100. package/src/zero-shot-classification/about.md +39 -0
  101. package/src/zero-shot-classification/data.ts +66 -0
  102. package/src/zero-shot-image-classification/about.md +68 -0
  103. package/src/zero-shot-image-classification/data.ts +79 -0
@@ -0,0 +1,56 @@
1
+ ## Use Cases
2
+
3
+ ### Frequently Asked Questions
4
+
5
+ You can use Question Answering (QA) models to automate the response to frequently asked questions by using a knowledge base (documents) as context. Answers to customer questions can be drawn from those documents.
6
+
7
+ ⚡⚡ If you’d like to save inference time, you can first use [passage ranking models](/tasks/sentence-similarity) to see which document might contain the answer to the question and iterate over that document with the QA model instead.
8
+
9
+ ## Task Variants
10
+ There are different QA variants based on the inputs and outputs:
11
+
12
+ - **Extractive QA:** The model **extracts** the answer from a context. The context here could be a provided text, a table or even HTML! This is usually solved with BERT-like models.
13
+ - **Open Generative QA:** The model **generates** free text directly based on the context. You can learn more about the Text Generation task in [its page](/tasks/text-generation).
14
+ - **Closed Generative QA:** In this case, no context is provided. The answer is completely generated by a model.
15
+
16
+ The schema above illustrates extractive, open book QA. The model takes a context and the question and extracts the answer from the given context.
17
+
18
+ You can also differentiate QA models depending on whether they are open-domain or closed-domain. Open-domain models are not restricted to a specific domain, while closed-domain models are restricted to a specific domain (e.g. legal, medical documents).
19
+
20
+ ## Inference
21
+
22
+ You can infer with QA models with the 🤗 Transformers library using the `question-answering` pipeline. If no model checkpoint is given, the pipeline will be initialized with `distilbert-base-cased-distilled-squad`. This pipeline takes a question and a context from which the answer will be extracted and returned.
23
+
24
+ ```python
25
+ from transformers import pipeline
26
+
27
+ qa_model = pipeline("question-answering")
28
+ question = "Where do I live?"
29
+ context = "My name is Merve and I live in İstanbul."
30
+ qa_model(question = question, context = context)
31
+ ## {'answer': 'İstanbul', 'end': 39, 'score': 0.953, 'start': 31}
32
+ ```
33
+
34
+ ## Useful Resources
35
+
36
+ Would you like to learn more about QA? Awesome! Here are some curated resources that you may find helpful!
37
+
38
+ - [Course Chapter on Question Answering](https://huggingface.co/course/chapter7/7?fw=pt)
39
+ - [Question Answering Workshop](https://www.youtube.com/watch?v=Ihgk8kGLpIE&ab_channel=HuggingFace)
40
+ - [How to Build an Open-Domain Question Answering System?](https://lilianweng.github.io/lil-log/2020/10/29/open-domain-question-answering.html)
41
+ - [Blog Post: ELI5 A Model for Open Domain Long Form Question Answering](https://yjernite.github.io/lfqa.html)
42
+
43
+ ### Notebooks
44
+
45
+ - [PyTorch](https://github.com/huggingface/notebooks/blob/master/examples/question_answering.ipynb)
46
+ - [TensorFlow](https://github.com/huggingface/notebooks/blob/main/examples/question_answering-tf.ipynb)
47
+
48
+ ### Scripts for training
49
+
50
+ - [PyTorch](https://github.com/huggingface/transformers/tree/main/examples/pytorch/question-answering)
51
+ - [TensorFlow](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/question-answering)
52
+ - [Flax](https://github.com/huggingface/transformers/tree/main/examples/flax/question-answering)
53
+
54
+ ### Documentation
55
+
56
+ - [Question answering task guide](https://huggingface.co/docs/transformers/tasks/question_answering)
@@ -0,0 +1,69 @@
1
+ import type { TaskDataCustom } from "../Types";
2
+
3
+ const taskData: TaskDataCustom = {
4
+ datasets: [
5
+ {
6
+ // TODO write proper description
7
+ description: "A famous question answering dataset based on English articles from Wikipedia.",
8
+ id: "squad_v2",
9
+ },
10
+ {
11
+ // TODO write proper description
12
+ description: "A dataset of aggregated anonymized actual queries issued to the Google search engine.",
13
+ id: "natural_questions",
14
+ },
15
+ ],
16
+ demo: {
17
+ inputs: [
18
+ {
19
+ label: "Question",
20
+ content: "Which name is also used to describe the Amazon rainforest in English?",
21
+ type: "text",
22
+ },
23
+ {
24
+ label: "Context",
25
+ content: "The Amazon rainforest, also known in English as Amazonia or the Amazon Jungle",
26
+ type: "text",
27
+ },
28
+ ],
29
+ outputs: [
30
+ {
31
+ label: "Answer",
32
+ content: "Amazonia",
33
+ type: "text",
34
+ },
35
+ ],
36
+ },
37
+ metrics: [
38
+ {
39
+ description: "Exact Match is a metric based on the strict character match of the predicted answer and the right answer. For answers predicted correctly, the Exact Match will be 1. Even if only one character is different, Exact Match will be 0",
40
+ id: "exact-match",
41
+ },
42
+ {
43
+ description: " The F1-Score metric is useful if we value both false positives and false negatives equally. The F1-Score is calculated on each word in the predicted sequence against the correct answer",
44
+ id: "f1",
45
+ },
46
+ ],
47
+ models: [
48
+ {
49
+ description: "A robust baseline model for most question answering domains.",
50
+ id: "deepset/roberta-base-squad2",
51
+ },
52
+ {
53
+ description: "A special model that can answer questions from tables!",
54
+ id: "google/tapas-base-finetuned-wtq",
55
+ },
56
+ ],
57
+ spaces: [
58
+ {
59
+ description: "An application that can answer a long question from Wikipedia.",
60
+ id: "deepset/wikipedia-assistant",
61
+ },
62
+ ],
63
+ summary: "Question Answering models can retrieve the answer to a question from a given text, which is useful for searching for an answer in a document. Some question answering models can generate answers without context!",
64
+ widgetModels: ["deepset/roberta-base-squad2"],
65
+ youtubeId: "ajPx5LwJD-I",
66
+ };
67
+
68
+
69
+ export default taskData;
@@ -0,0 +1,176 @@
1
+ ## Use Cases
2
+
3
+ ### Gaming
4
+
5
+ Reinforcement learning is known for its application to video games. Since the games provide a safe environment for the agent to be trained in the sense that it is perfectly defined and controllable, this makes them perfect candidates for experimentation and will help a lot to learn about the capabilities and limitations of various RL algorithms.
6
+
7
+
8
+ There are many videos on the Internet where a game-playing reinforcement learning agent starts with a terrible gaming strategy due to random initialization of its settings, but over iterations, the agent gets better and better with each episode of the training. This [paper](https://arxiv.org/abs/1912.10944) mainly investigates the performance of RL in popular games such as Minecraft or Dota2. The agent's performance can exceed a human player's, although there are still some challenges mainly related to efficiency in constructing the gaming policy of the reinforcement learning agent.
9
+
10
+
11
+ ### Trading and Finance
12
+ Reinforcement learning is the science to train computers to make decisions and thus has a novel use in trading and finance. All time-series models are helpful in predicting prices, volume and future sales of a product or a stock. Reinforcement based automated agents can decide to sell, buy or hold a stock. It shifts the impact of AI in this field to real time decision making rather than just prediction of prices. The glossary given below will clear some parameters to as to how we can train a model to take these decisions.
13
+
14
+
15
+
16
+ ## Task Variants
17
+
18
+ ### Model Based RL
19
+ In model based reinforcement learning techniques intend to create a model of the environment, learn the state transition probabilities and the reward function, to find the optimal action. Some typical examples for model based reinforcement learning algorithms are dynamic programming, value iteration and policy iteration.
20
+
21
+
22
+ ### Model Free RL
23
+ In model free reinforcement learning, agent decides on optimal actions based on its experience in the environment and the reward it collects from it. This is one of the most commonly used algorithms beneficial in complex environments, where modeling of state transition probabilities and reward functions are difficult. Some of the examples of model free reinforcement learning are SARSA, Q-Learning, actor-critic and proximal policy optimization (PPO) algorithms.
24
+
25
+
26
+ ## Glossary
27
+
28
+ <!-- ![RL Loop](https://huggingface.co/blog/assets/63_deep_rl_intro/RL_process.jpg "Agent Environment Interaction") TODO: Uncomment image for visual understanding if it fits within the page-->
29
+
30
+
31
+ **Agent:** The learner and the decision maker.
32
+
33
+
34
+ **Environment:** The part of the world the agent interacts, comprising everything outside the agent.
35
+
36
+
37
+ Observations and states are the information our agent gets from the environment. In the case of a video game, it can be a frame (a screenshot). In the case of the trading agent, it can be the value of a certain stock.
38
+
39
+
40
+ **State:** Complete description of the state of the environment with no hidden information.
41
+
42
+
43
+ **Observation:** Partial description of the state, in a partially observed environment.
44
+
45
+
46
+
47
+ **Action:** The decision taken by the agent.
48
+
49
+ **Reward:** The numerical feedback signal that the agent receives from the environment based on the chosen action.
50
+
51
+
52
+ **Return:** Cumulative Reward. In the simplest case, the return is the sum of the rewards.
53
+
54
+
55
+ **Episode:** For some applications there is a natural notion of final time step. In this case, there is a starting point and an ending point (a terminal state). This creates an episode: a list of States, Actions, Rewards, and new States. For instance, think about Chess: an episode begins at the initial board position and ends when the game is over.
56
+
57
+ **Policy:** The Policy is the brain of the Agent, it’s the function that tells what action to take given the state. So it defines the agent’s behavior at a given time. Reinforcement learning methods specify how the agent’s policy is changed as a result of its experience.
58
+
59
+ ## Inference
60
+
61
+ Inference in reinforcement learning differs from other modalities, in which there's a model and test data. In reinforcement learning, once you have trained an agent in an environment, you try to run the trained agent for additional steps to get the average reward.
62
+
63
+ A typical training cycle consists of gathering experience from the environment, training the agent, and running the agent on a test environment to obtain average reward. Below there's a snippet on how you can interact with the environment using the `gymnasium` library, train an agent using `stable-baselines3`, evalute the agent on test environment and infer actions from the trained agent.
64
+
65
+
66
+ ```python
67
+ # Here we are running 20 episodes of CartPole-v1 environment, taking random actions
68
+ import gymnasium as gym
69
+
70
+ env = gym.make("CartPole-v1")
71
+ observation, info = env.reset()
72
+
73
+ for _ in range(20):
74
+ action = env.action_space.sample() # samples random action from action sample space
75
+
76
+ # the agent takes the action
77
+ observation, reward, terminated, truncated, info = env.step(action)
78
+
79
+
80
+ # if the agent reaches terminal state, we reset the environment
81
+ if terminated or truncated:
82
+
83
+ print("Environment is reset")
84
+ observation = env.reset()
85
+
86
+ env.close()
87
+ ```
88
+
89
+ Below snippet shows how to train a PPO model on LunarLander-v2 environment using `stable-baselines3` library and saving the model
90
+ ```python
91
+ from stable_baselines3 import PPO
92
+
93
+ # initialize the environment
94
+
95
+ env = gym.make("LunarLander-v2")
96
+
97
+ # initialize the model
98
+
99
+ model = PPO(policy = "MlpPolicy",
100
+ env = env,
101
+ n_steps = 1024,
102
+ batch_size = 64,
103
+ n_epochs = 4,
104
+ verbose = 1)
105
+
106
+ # train the model for 1000 time steps
107
+ model.learn(total_timesteps = 1000)
108
+
109
+ # Saving the model in desired directory
110
+ model_name = "PPO-LunarLander-v2"
111
+ model.save(model_name)
112
+ ```
113
+ Below code shows how to evaluate an agent trained using `stable-baselines3`
114
+ ```python
115
+ # Loading a saved model and evaluating the model for 10 episodes
116
+ from stable_baselines3.common.evaluation import evaluate_policy
117
+ from stable_baselines3 import PPO
118
+
119
+
120
+ env = gym.make("LunarLander-v2")
121
+ # Loading the saved model
122
+ model = PPO.load("PPO-LunarLander-v2",env=env)
123
+
124
+ # Initializating the evaluation environment
125
+ eval_env = gym.make("LunarLander-v2")
126
+
127
+ # Running the trained agent on eval_env for 10 time steps and getting the mean reward
128
+ mean_reward, std_reward = evaluate_policy(model, eval_env, n_eval_episodes = 10,
129
+ deterministic=True)
130
+
131
+ print(f"mean_reward={mean_reward:.2f} +/- {std_reward}")
132
+ ```
133
+
134
+ Below code snippet shows how to infer actions from an agent trained using `stable-baselines3`
135
+
136
+ ```python
137
+ from stable_baselines3.common.evaluation import evaluate_policy
138
+ from stable_baselines3 import PPO
139
+
140
+ # Loading the saved model
141
+ model = PPO.load("PPO-LunarLander-v2",env=env)
142
+
143
+ # Getting the environment from the trained agent
144
+ env = model.get_env()
145
+
146
+ obs = env.reset()
147
+ for i in range(1000):
148
+ # getting action predictions from the trained agent
149
+ action, _states = model.predict(obs, deterministic=True)
150
+
151
+ # taking the predicted action in the environment to observe next state and rewards
152
+ obs, rewards, dones, info = env.step(action)
153
+ ```
154
+
155
+ For more information, you can check out the documentations of the respective libraries.
156
+
157
+ [Gymnasium Documentation](https://gymnasium.farama.org/)
158
+ [Stable Baselines Documentation](https://stable-baselines3.readthedocs.io/en/master/)
159
+
160
+ ## Useful Resources
161
+
162
+ Would you like to learn more about the topic? Awesome! Here you can find some curated resources that you may find helpful!
163
+
164
+ - [HuggingFace Deep Reinforcement Learning Class](https://github.com/huggingface/deep-rl-class)
165
+ - [Introduction to Deep Reinforcement Learning](https://huggingface.co/blog/deep-rl-intro)
166
+ - [Stable Baselines Integration with HuggingFace](https://huggingface.co/blog/sb3)
167
+ - Learn how reinforcement learning is used in conversational agents in this blog: [Illustrating Reinforcement Learning from Human Feedback (RLHF)](https://huggingface.co/blog/rlhf)
168
+ - [Reinforcement Learning from Human Feedback From Zero to ChatGPT](https://www.youtube.com/watch?v=EAd4oQtEJOM)
169
+ - [Guide on Multi-Agent Competition Systems](https://huggingface.co/blog/aivsai)
170
+
171
+ ### Notebooks
172
+ - [Train a Deep Reinforcement Learning lander agent to land correctly on the Moon 🌕 using Stable-Baselines3](https://github.com/huggingface/deep-rl-class/blob/main/notebooks/unit1/unit1.ipynb)
173
+ - [Introduction to Unity MLAgents](https://github.com/huggingface/deep-rl-class/blob/main/notebooks/unit5/unit5.ipynb)
174
+ - [Training Decision Transformers with 🤗 transformers](https://github.com/huggingface/blog/blob/main/notebooks/101_train-decision-transformers.ipynb)
175
+
176
+ This page was made possible thanks to the efforts of [Ram Ananth](https://huggingface.co/RamAnanth1), [Emilio Lehoucq](https://huggingface.co/emiliol), [Sagar Mathpal](https://huggingface.co/sagarmathpal) and [Osman Alenbey](https://huggingface.co/osman93).
@@ -0,0 +1,78 @@
1
+ import type { TaskDataCustom } from "../Types";
2
+
3
+ const taskData: TaskDataCustom = {
4
+ datasets: [
5
+ {
6
+ description:
7
+ "A curation of widely used datasets for Data Driven Deep Reinforcement Learning (D4RL)",
8
+ id: "edbeeching/decision_transformer_gym_replay",
9
+ },
10
+ ],
11
+ demo: {
12
+ inputs: [
13
+ {
14
+ label: "State",
15
+ content: "Red traffic light, pedestrians are about to pass.",
16
+ type: "text",
17
+ },
18
+ ],
19
+ outputs: [
20
+ {
21
+ label: "Action",
22
+ content: "Stop the car.",
23
+ type: "text",
24
+ },
25
+ {
26
+ label: "Next State",
27
+ content: "Yellow light, pedestrians have crossed.",
28
+ type: "text",
29
+ },
30
+ ],
31
+ },
32
+ metrics: [
33
+ {
34
+ description:
35
+ "Accumulated reward across all time steps discounted by a factor that ranges between 0 and 1 and determines how much the agent optimizes for future relative to immediate rewards. Measures how good is the policy ultimately found by a given algorithm considering uncertainty over the future.",
36
+ id: "Discounted Total Reward",
37
+ },
38
+ {
39
+ description:
40
+ "Average return obtained after running the policy for a certain number of evaluation episodes. As opposed to total reward, mean reward considers how much reward a given algorithm receives while learning.",
41
+ id: "Mean Reward",
42
+ },
43
+ {
44
+ description:
45
+ "Measures how good a given algorithm is after a predefined time. Some algorithms may be guaranteed to converge to optimal behavior across many time steps. However, an agent that reaches an acceptable level of optimality after a given time horizon may be preferable to one that ultimately reaches optimality but takes a long time.",
46
+ id: "Level of Performance After Some Time",
47
+ },
48
+ ],
49
+ models: [
50
+ {
51
+ description:
52
+ "A Reinforcement Learning model trained on expert data from the Gym Hopper environment",
53
+
54
+ id: "edbeeching/decision-transformer-gym-hopper-expert",
55
+ },
56
+ {
57
+ description:
58
+ "A PPO agent playing seals/CartPole-v0 using the stable-baselines3 library and the RL Zoo.",
59
+ id: "HumanCompatibleAI/ppo-seals-CartPole-v0",
60
+ },
61
+ ],
62
+ spaces: [
63
+ {
64
+ description: "An application for a cute puppy agent learning to catch a stick.",
65
+ id: "ThomasSimonini/Huggy",
66
+ },
67
+ {
68
+ description: "An application to play Snowball Fight with a reinforcement learning agent.",
69
+ id: "ThomasSimonini/SnowballFight",
70
+ },
71
+ ],
72
+ summary:
73
+ "Reinforcement learning is the computational approach of learning from action by interacting with an environment through trial and error and receiving rewards (negative or positive) as feedback",
74
+ widgetModels: [],
75
+ youtubeId: "q0BiUn5LiBc",
76
+ };
77
+
78
+ export default taskData;
@@ -0,0 +1,97 @@
1
+ ## Use Cases 🔍
2
+
3
+ ### Information Retrieval
4
+
5
+ You can extract information from documents using Sentence Similarity models. The first step is to rank documents using Passage Ranking models. You can then get to the top ranked document and search it with Sentence Similarity models by selecting the sentence that has the most similarity to the input query.
6
+
7
+ ## The Sentence Transformers library
8
+
9
+ The [Sentence Transformers](https://www.sbert.net/) library is very powerful for calculating embeddings of sentences, paragraphs, and entire documents. An embedding is just a vector representation of a text and is useful for finding how similar two texts are.
10
+
11
+ You can find and use [hundreds of Sentence Transformers](https://huggingface.co/models?library=sentence-transformers&sort=downloads) models from the Hub by directly using the library, playing with the widgets in the browser or using the Inference API.
12
+
13
+ ## Task Variants
14
+
15
+ ### Passage Ranking
16
+
17
+ Passage Ranking is the task of ranking documents based on their relevance to a given query. The task is evaluated on Mean Reciprocal Rank. These models take one query and multiple documents and return ranked documents according to the relevancy to the query. 📄
18
+
19
+ You can infer with Passage Ranking models using the [Inference API](https://huggingface.co/inference-api). The Passage Ranking model inputs are a query for which we look for relevancy in the documents and the documents we want to search. The model will return scores according to the relevancy of these documents for the query.
20
+
21
+ ```python
22
+ import json
23
+ import requests
24
+
25
+ API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/msmarco-distilbert-base-tas-b"
26
+ headers = {"Authorization": f"Bearer {api_token}"}
27
+
28
+ def query(payload):
29
+ response = requests.post(API_URL, headers=headers, json=payload)
30
+ return response.json()
31
+
32
+ data = query(
33
+ {
34
+ "inputs": {
35
+ "source_sentence": "That is a happy person",
36
+ "sentences": [
37
+ "That is a happy dog",
38
+ "That is a very happy person",
39
+ "Today is a sunny day"
40
+ ]
41
+ }
42
+ }
43
+ ## [0.853, 0.981, 0.655]
44
+ ```
45
+
46
+ ### Semantic Textual Similarity
47
+
48
+ Semantic Textual Similarity is the task of evaluating how similar two texts are in terms of meaning. These models take a source sentence and a list of sentences in which we will look for similarities and will return a list of similarity scores. The benchmark dataset is the [Semantic Textual Similarity Benchmark](http://ixa2.si.ehu.eus/stswiki/index.php/STSbenchmark). The task is evaluated on Pearson’s Rank Correlation.
49
+
50
+ ```python
51
+ import json
52
+ import requests
53
+
54
+ API_URL = "https://api-inference.huggingface.co/models/sentence-transformers/all-MiniLM-L6-v2"
55
+ headers = {"Authorization": f"Bearer {api_token}"}
56
+
57
+ def query(payload):
58
+ response = requests.post(API_URL, headers=headers, json=payload)
59
+ return response.json()
60
+
61
+ data = query(
62
+ {
63
+ "inputs": {
64
+ "source_sentence": "I'm very happy",
65
+ "sentences":["I'm filled with happiness", "I'm happy"]
66
+ }
67
+ })
68
+
69
+ ## [0.605, 0.894]
70
+ ```
71
+
72
+ You can also infer with the models in the Hub using Sentence Transformer models.
73
+
74
+ ```python
75
+ pip install -U sentence-transformers
76
+
77
+ from sentence_transformers import SentenceTransformer, util
78
+ sentences = ["I'm happy", "I'm full of happiness"]
79
+
80
+ model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
81
+
82
+ #Compute embedding for both lists
83
+ embedding_1= model.encode(sentences[0], convert_to_tensor=True)
84
+ embedding_2 = model.encode(sentences[1], convert_to_tensor=True)
85
+
86
+ util.pytorch_cos_sim(embedding_1, embedding_2)
87
+ ## tensor([[0.6003]])
88
+ ```
89
+
90
+ ## Useful Resources
91
+
92
+ Would you like to learn more about Sentence Transformers and Sentence Similarity? Awesome! Here you can find some curated resources that you may find helpful!
93
+
94
+ - [Sentence Transformers Documentation](https://www.sbert.net/)
95
+ - [Sentence Transformers in the Hub](https://huggingface.co/blog/sentence-transformers-in-the-hub)
96
+ - [Building a Playlist Generator with Sentence Transformers](https://huggingface.co/blog/playlist-generator)
97
+ - [Getting Started With Embeddings](https://huggingface.co/blog/getting-started-with-embeddings)
@@ -0,0 +1,100 @@
1
+ import type { TaskDataCustom } from "../Types";
2
+
3
+ const taskData: TaskDataCustom = {
4
+ datasets: [
5
+ {
6
+ description: "Bing queries with relevant passages from various web sources.",
7
+ id: "ms_marco",
8
+ },
9
+
10
+ ],
11
+ demo: {
12
+ inputs: [
13
+
14
+
15
+ {
16
+ label: "Source sentence",
17
+ content: "Machine learning is so easy.",
18
+ type: "text",
19
+ },
20
+ {
21
+ label: "Sentences to compare to",
22
+ content: "Deep learning is so straightforward.",
23
+ type: "text",
24
+ },
25
+ {
26
+ label: "",
27
+ content: "This is so difficult, like rocket science.",
28
+ type: "text",
29
+ },
30
+ {
31
+ label: "",
32
+ content: "I can't believe how much I struggled with this.",
33
+ type: "text",
34
+ },
35
+
36
+ ],
37
+ outputs: [
38
+ {
39
+ type: "chart",
40
+ data: [
41
+ {
42
+ label: "Deep learning is so straightforward.",
43
+ score: 0.623,
44
+ },
45
+ {
46
+ label: "This is so difficult, like rocket science.",
47
+ score: 0.413,
48
+ },
49
+ {
50
+ label: "I can't believe how much I struggled with this.",
51
+ score: 0.256,
52
+ },
53
+ ],
54
+ },
55
+ ],
56
+ },
57
+ metrics: [
58
+ {
59
+ description: "Reciprocal Rank is a measure used to rank the relevancy of documents given a set of documents. Reciprocal Rank is the reciprocal of the rank of the document retrieved, meaning, if the rank is 3, the Reciprocal Rank is 0.33. If the rank is 1, the Reciprocal Rank is 1",
60
+ id: "Mean Reciprocal Rank",
61
+ },
62
+ {
63
+ description: "The similarity of the embeddings is evaluated mainly on cosine similarity. It is calculated as the cosine of the angle between two vectors. It is particularly useful when your texts are not the same length",
64
+ id: "Cosine Similarity",
65
+ },
66
+ ],
67
+ models: [
68
+ {
69
+ description: "This model works well for sentences and paragraphs and can be used for clustering/grouping and semantic searches.",
70
+ id: "sentence-transformers/all-mpnet-base-v2",
71
+ },
72
+ {
73
+ description: "A multilingual model trained for FAQ retrieval.",
74
+ id: "clips/mfaq",
75
+ },
76
+ ],
77
+ spaces: [
78
+ {
79
+ description: "An application that leverages sentence similarity to answer questions from YouTube videos.",
80
+ id: "Gradio-Blocks/Ask_Questions_To_YouTube_Videos",
81
+ },
82
+ {
83
+ description: "An application that retrieves relevant PubMed abstracts for a given online article which can be used as further references.",
84
+ id: "Gradio-Blocks/pubmed-abstract-retriever",
85
+ },
86
+ {
87
+ description: "An application that leverages sentence similarity to summarize text.",
88
+ id: "nickmuchi/article-text-summarizer",
89
+ },
90
+ {
91
+ description: "A guide that explains how Sentence Transformers can be used for semantic search.",
92
+ id: "sentence-transformers/Sentence_Transformers_for_semantic_search",
93
+ },
94
+ ],
95
+ summary: "Sentence Similarity is the task of determining how similar two texts are. Sentence similarity models convert input texts into vectors (embeddings) that capture semantic information and calculate how close (similar) they are between them. This task is particularly useful for information retrieval and clustering/grouping.",
96
+ widgetModels: ["sentence-transformers/all-MiniLM-L6-v2"],
97
+ youtubeId: "VCZq5AkbNEU",
98
+ };
99
+
100
+ export default taskData;
@@ -0,0 +1,57 @@
1
+ ## Use Cases
2
+
3
+ ### Research Paper Summarization 🧐
4
+
5
+ Research papers can be summarized to allow researchers to spend less time selecting which articles to read. There are several approaches you can take for a task like this:
6
+
7
+ 1. Use an existing extractive summarization model on the Hub to do inference.
8
+ 2. Pick an existing language model trained for academic papers. This model can then be trained in a process called fine-tuning so it can solve the summarization task.
9
+ 3. Use a sequence-to-sequence model like [T5](https://huggingface.co/docs/transformers/model_doc/t5) for abstractive text summarization.
10
+
11
+ ## Inference
12
+
13
+ You can use the 🤗 Transformers library `summarization` pipeline to infer with existing Summarization models. If no model name is provided the pipeline will be initialized with [sshleifer/distilbart-cnn-12-6](https://huggingface.co/sshleifer/distilbart-cnn-12-6).
14
+
15
+ ```python
16
+ from transformers import pipeline
17
+
18
+ classifier = pipeline("summarization")
19
+ classifier("Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent of the population of France as of 2017.")
20
+ ## [{ "summary_text": " Paris is the capital and most populous city of France..." }]
21
+ ```
22
+
23
+ You can use [huggingface.js](https://github.com/huggingface/huggingface.js) to infer summarization models on Hugging Face Hub.
24
+
25
+ ```javascript
26
+ import { HfInference } from "@huggingface/inference";
27
+
28
+ const inference = new HfInference(HF_ACCESS_TOKEN);
29
+ const inputs = "Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents as of 2018, in an area of more than 105 square kilometres (41 square miles). The City of Paris is the centre and seat of government of the region and province of Île-de-France, or Paris Region, which has an estimated population of 12,174,880, or about 18 percent of the population of France as of 2017."
30
+
31
+ await inference.summarization({
32
+ model: 'sshleifer/distilbart-cnn-12-6',
33
+ inputs
34
+ })
35
+ ```
36
+
37
+ ## Useful Resources
38
+
39
+ Would you like to learn more about the topic? Awesome! Here you can find some curated resources that you may find helpful!
40
+
41
+ - [Course Chapter on Summarization](https://huggingface.co/course/chapter7/5?fw=pt)
42
+ - [Distributed Training: Train BART/T5 for Summarization using 🤗 Transformers and Amazon SageMaker](https://huggingface.co/blog/sagemaker-distributed-training-seq2seq)
43
+
44
+ ### Notebooks
45
+
46
+ - [PyTorch](https://github.com/huggingface/notebooks/blob/master/examples/summarization.ipynb)
47
+ - [TensorFlow](https://github.com/huggingface/notebooks/blob/master/examples/summarization-tf.ipynb)
48
+
49
+ ### Scripts for training
50
+
51
+ - [PyTorch](https://github.com/huggingface/transformers/tree/main/examples/pytorch/summarization)
52
+ - [TensorFlow](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/summarization)
53
+ - [Flax](https://github.com/huggingface/transformers/tree/main/examples/flax/summarization)
54
+
55
+ ### Documentation
56
+
57
+ - [Summarization task guide](https://huggingface.co/docs/transformers/tasks/summarization)