Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,6 +74,7 @@ HF_REFERENCE_HTML = """
|
|
| 74 |
<p>
|
| 75 |
A story generation model can receive an input like "Once upon a time" and proceed to create a story-like text based on those first words.
|
| 76 |
You can try <a href="https://huggingface.co/spaces/mosaicml/mpt-7b-storywriter">this application</a> which contains a model trained on story generation, by MosaicML.
|
|
|
|
| 77 |
If your generative model training data is different than your use case, you can train a causal language model from scratch.
|
| 78 |
Learn how to do it in the free transformers <a href="https://huggingface.co/course/chapter7/6?fw=pt">course</a>!
|
| 79 |
</p>
|
|
@@ -103,9 +104,9 @@ HF_REFERENCE_HTML = """
|
|
| 103 |
<h3>Language Model Variants</h3>
|
| 104 |
When it comes to text generation, the underlying language model can come in several types:
|
| 105 |
<ul>
|
| 106 |
-
<li>Base models: refers to plain language models like Mistral 7B and Meta Llama-3-70b. These models are good for fine-tuning and few-shot prompting.
|
| 107 |
-
<li>Instruction-trained models: these models are trained in a multi-task manner to follow a broad range of instructions like "Write me a recipe for chocolate cake". Models like Qwen 2 7B, Yi 1.5 34B Chat, and Meta Llama 70B Instruct are examples of instruction-trained models. In general, instruction-trained models will produce better responses to instructions than base models.
|
| 108 |
-
<li>Human feedback models: these models extend base and instruction-trained models by incorporating human feedback that rates the quality of the generated text according to criteria like helpfulness, honesty, and harmlessness. The human feedback is then combined with an optimization technique like reinforcement learning to align the original model to be closer with human preferences. The overall methodology is often called Reinforcement Learning from Human Feedback, or RLHF for short. Zephyr ORPO 141B A35B is an open-source model aligned through human feedback.
|
| 109 |
</ul>
|
| 110 |
<h2>Text Generation from Image and Text</h2>
|
| 111 |
<p>
|
|
@@ -127,6 +128,36 @@ from transformers import pipeline
|
|
| 127 |
generator = pipeline('text-generation', model='gpt2')
|
| 128 |
generator("Hello, I'm a language model,", max_length=30, num_return_sequences=3)
|
| 129 |
</pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
<h2>Text Generation Inference</h2>
|
| 132 |
<p>
|
|
@@ -179,11 +210,11 @@ document.addEventListener("mouseup", () => {
|
|
| 179 |
|
| 180 |
content_display = gr.HTML(YOUR_WORK_HTML)
|
| 181 |
|
| 182 |
-
view_toggle.change(
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
)
|
| 187 |
|
| 188 |
selected_text = gr.Textbox(
|
| 189 |
label="Selected text",
|
|
|
|
| 74 |
<p>
|
| 75 |
A story generation model can receive an input like "Once upon a time" and proceed to create a story-like text based on those first words.
|
| 76 |
You can try <a href="https://huggingface.co/spaces/mosaicml/mpt-7b-storywriter">this application</a> which contains a model trained on story generation, by MosaicML.
|
| 77 |
+
|
| 78 |
If your generative model training data is different than your use case, you can train a causal language model from scratch.
|
| 79 |
Learn how to do it in the free transformers <a href="https://huggingface.co/course/chapter7/6?fw=pt">course</a>!
|
| 80 |
</p>
|
|
|
|
| 104 |
<h3>Language Model Variants</h3>
|
| 105 |
When it comes to text generation, the underlying language model can come in several types:
|
| 106 |
<ul>
|
| 107 |
+
<li><b>Base models</b>: refers to plain language models like Mistral 7B and Meta Llama-3-70b. These models are good for fine-tuning and few-shot prompting.
|
| 108 |
+
<li><b>Instruction-trained models</b>: these models are trained in a multi-task manner to follow a broad range of instructions like "Write me a recipe for chocolate cake". Models like Qwen 2 7B, Yi 1.5 34B Chat, and Meta Llama 70B Instruct are examples of instruction-trained models. In general, instruction-trained models will produce better responses to instructions than base models.
|
| 109 |
+
<li><b>Human feedback models</b>: these models extend base and instruction-trained models by incorporating human feedback that rates the quality of the generated text according to criteria like helpfulness, honesty, and harmlessness. The human feedback is then combined with an optimization technique like reinforcement learning to align the original model to be closer with human preferences. The overall methodology is often called Reinforcement Learning from Human Feedback, or RLHF for short. Zephyr ORPO 141B A35B is an open-source model aligned through human feedback.
|
| 110 |
</ul>
|
| 111 |
<h2>Text Generation from Image and Text</h2>
|
| 112 |
<p>
|
|
|
|
| 128 |
generator = pipeline('text-generation', model='gpt2')
|
| 129 |
generator("Hello, I'm a language model,", max_length=30, num_return_sequences=3)
|
| 130 |
</pre>
|
| 131 |
+
|
| 132 |
+
<p>
|
| 133 |
+
Text-to-Text generation models have a separate pipeline called text2text-generation.
|
| 134 |
+
This pipeline takes an input containing the sentence including the task and returns the output of the accomplished task.
|
| 135 |
+
<p>
|
| 136 |
+
|
| 137 |
+
<pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
|
| 138 |
+
from transformers import pipeline
|
| 139 |
+
|
| 140 |
+
text2text_generator = pipeline("text2text-generation")
|
| 141 |
+
text2text_generator("question: What is 42 ? context: 42 is the answer to life, the universe and everything")
|
| 142 |
+
[{'generated_text': 'the answer to life, the universe and everything'}]
|
| 143 |
+
|
| 144 |
+
text2text_generator("translate from English to French: I'm very happy")
|
| 145 |
+
[{'generated_text': 'Je suis très heureux'}]
|
| 146 |
+
</pre>
|
| 147 |
+
|
| 148 |
+
<p>
|
| 149 |
+
You can use huggingface.js to infer text classification models on Hugging Face Hub.
|
| 150 |
+
</p>
|
| 151 |
+
|
| 152 |
+
<pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
|
| 153 |
+
import { InferenceClient } from "@huggingface/inference";
|
| 154 |
+
|
| 155 |
+
const inference = new InferenceClient(HF_TOKEN);
|
| 156 |
+
await inference.conversational({
|
| 157 |
+
model: "distilbert-base-uncased-finetuned-sst-2-english",
|
| 158 |
+
inputs: "I love this movie!",
|
| 159 |
+
});
|
| 160 |
+
</pre>
|
| 161 |
|
| 162 |
<h2>Text Generation Inference</h2>
|
| 163 |
<p>
|
|
|
|
| 210 |
|
| 211 |
content_display = gr.HTML(YOUR_WORK_HTML)
|
| 212 |
|
| 213 |
+
#view_toggle.change(
|
| 214 |
+
# fn=switch_content,
|
| 215 |
+
# inputs=view_toggle,
|
| 216 |
+
# outputs=content_display
|
| 217 |
+
#)
|
| 218 |
|
| 219 |
selected_text = gr.Textbox(
|
| 220 |
label="Selected text",
|