TheHickman commited on
Commit
c8f7070
·
verified ·
1 Parent(s): 405ab1c

Made hugging face close to exact replica

Browse files
Files changed (1) hide show
  1. app.py +72 -84
app.py CHANGED
@@ -49,37 +49,81 @@ YOUR_WORK_HTML = """
49
  HF_REFERENCE_HTML = """
50
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
51
  <h1>Text Generation (Hugging Face Reference)</h1>
52
-
53
- <h2>What is text generation?</h2>
54
  <p>
55
- Text generation is the task of generating new text given another text. These models can,
56
- for example, fill in incomplete text or paraphrase.
 
57
  </p>
58
 
59
  <h2>Use Cases</h2>
60
 
61
- <h3>Story Generation</h3>
62
- <p>Models can be used to generate creative stories given a prompt.</p>
 
 
 
63
 
64
  <h3>Code Generation</h3>
65
- <p>Models can help developers by generating code snippets or entire functions.</p>
 
 
 
66
 
67
- <h3>Text Completion</h3>
68
- <p>Text generation models can autocomplete sentences or fill in missing words.</p>
 
 
 
 
 
 
69
 
70
  <h2>Task Variants</h2>
71
 
72
  <h3>Completion Generation Models</h3>
73
  <p>
74
- In this task, the model is trained to predict the next word(s) given an input sequence.
75
- GPT-2 and GPT-3 are examples of this.
 
 
 
 
 
 
 
 
 
 
76
  </p>
77
 
78
  <h3>Text-to-Text Generation Models</h3>
79
  <p>
80
- Some text generation models are trained in a text-to-text manner. T5 and BART are examples
81
- of this, where the model is trained to generate text given another text as input
82
- (e.g., translation, summarization).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  </p>
84
 
85
  <h2>Inference</h2>
@@ -87,6 +131,7 @@ HF_REFERENCE_HTML = """
87
  You can use the 🤗 Transformers library <code>text-generation</code> pipeline to do inference
88
  with text generation models. It takes an input text and generates a continuation of that text.
89
  </p>
 
90
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
91
  from transformers import pipeline
92
 
@@ -94,76 +139,19 @@ generator = pipeline('text-generation', model='gpt2')
94
  generator("Hello, I'm a language model,", max_length=30, num_return_sequences=3)
95
  </pre>
96
 
97
- <h2>Popular Models</h2>
98
- <ul>
99
- <li>GPT-2</li>
100
- <li>GPT-Neo</li>
101
- <li>GPT-J</li>
102
- <li>BLOOM</li>
103
- <li>LLaMA</li>
104
- <li>Falcon</li>
105
- <li>Mistral</li>
106
- <li>Phi</li>
107
- </ul>
108
- <p>These models vary in size from millions to hundreds of billions of parameters.</p>
109
-
110
- <h2>Example Applications</h2>
111
-
112
- <h3>Creative Writing Assistant</h3>
113
- <p>
114
- Use text generation to help with creative writing by suggesting plot developments,
115
- character dialogues, or descriptive passages.
116
- </p>
117
-
118
- <h3>Chatbots and Conversational AI</h3>
119
- <p>Many modern chatbots use text generation models to provide natural, contextual responses.</p>
120
-
121
- <h3>Content Creation</h3>
122
- <p>Generate blog posts, product descriptions, social media content, and marketing copy.</p>
123
-
124
- <h3>Programming Assistance</h3>
125
- <p>
126
- Code generation models can help developers write code faster by suggesting completions,
127
- explaining code, or generating boilerplate.
128
- </p>
129
-
130
- <h2>Training</h2>
131
- <p>
132
- Text generation models are typically trained on large corpora of text using causal language
133
- modeling, where the model learns to predict the next token given previous tokens.
134
- </p>
135
-
136
- <h3>Common training objectives:</h3>
137
- <ul>
138
- <li><strong>Causal Language Modeling (CLM):</strong> Predict next token (GPT-style)</li>
139
- <li><strong>Masked Language Modeling (MLM):</strong> Predict masked tokens (BERT-style, though BERT isn't typically used for generation)</li>
140
- <li><strong>Sequence-to-Sequence:</strong> Map input text to output text (T5, BART)</li>
141
- </ul>
142
-
143
- <h2>Metrics</h2>
144
- <p>Common metrics for evaluating text generation:</p>
145
- <ul>
146
- <li><strong>Perplexity:</strong> Measures how well the model predicts the test data</li>
147
- <li><strong>BLEU:</strong> Measures overlap with reference texts (common for translation)</li>
148
- <li><strong>ROUGE:</strong> Measures overlap, often used for summarization</li>
149
- <li><strong>Human Evaluation:</strong> Often the gold standard for creative tasks</li>
150
- </ul>
151
-
152
- <h2>Ethical Considerations</h2>
153
- <p>Text generation models can:</p>
154
- <ul>
155
- <li>Generate biased or harmful content based on training data</li>
156
- <li>Be misused to create misleading information or spam</li>
157
- <li>Reproduce and amplify stereotypes present in training data</li>
158
- </ul>
159
-
160
- <p>It's important to:</p>
161
- <ul>
162
- <li>Carefully curate training data</li>
163
- <li>Implement content filters</li>
164
- <li>Be transparent about model capabilities and limitations</li>
165
- <li>Consider the societal impact of deployed systems</li>
166
- </ul>
167
  </div>
168
  """
169
 
 
49
  HF_REFERENCE_HTML = """
50
  <div id="hf-content" style="max-width: 800px; margin: auto; font-size: 16px; line-height: 1.6;">
51
  <h1>Text Generation (Hugging Face Reference)</h1>
52
+
53
+ <h1>About Text Generation</h1>
54
  <p>
55
+ This task covers guides on both <a href="https://huggingface.co/models?pipeline_tag=text-generation&sort=downloads">text-generation</a> and <a href="https://huggingface.co/models?other=text2text-generation&sort=downloads">text-to-text generation</a> models.
56
+ Popular large language models that are used for chats or following instructions are also covered in this task.
57
+ You can find the list of selected open-source large language models <a href="https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard">here</a>, ranked by their performance scores.
58
  </p>
59
 
60
  <h2>Use Cases</h2>
61
 
62
+ <h3>Instruction Models</h3>
63
+ <p>
64
+ A model trained for text generation can be later adapted to follow instructions.
65
+ You can try some of the most powerful instruction-tuned open-access models like Mixtral 8x7B, Cohere Command R+, and Meta Llama3 70B at <a href="https://huggingface.co/chat">Hugging Chat</a>.
66
+ </p>
67
 
68
  <h3>Code Generation</h3>
69
+ <p>
70
+ A Text Generation model, also known as a causal language model, can be trained on code from scratch to help the programmers in their repetitive coding tasks.
71
+ One of the most popular open-source models for code generation is StarCoder, which can generate code in 80+ languages. You can try it <a href="https://huggingface.co/spaces/bigcode/bigcode-playground">here</a>.
72
+ </p>
73
 
74
+ <h3>Stories Generation</h3>
75
+ <p>
76
+ 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.
77
+ 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.
78
+
79
+ If your generative model training data is different than your use case, you can train a causal language model from scratch.
80
+ Learn how to do it in the free transformers <a href="https://huggingface.co/course/chapter7/6?fw=pt">course</a>!
81
+ </p>
82
 
83
  <h2>Task Variants</h2>
84
 
85
  <h3>Completion Generation Models</h3>
86
  <p>
87
+ A popular variant of Text Generation models predicts the next word given a bunch of words.
88
+ Word by word a longer text is formed that results in for example:
89
+
90
+ <ul>
91
+ <li>Given an incomplete sentence, complete it.
92
+ <li>Continue a story given the first sentences.
93
+ <li>Provided a code description, generate the code.
94
+ </ul>
95
+
96
+ The most popular models for this task are GPT-based models, Mistral or Llama series.
97
+ These models are trained on data that has no labels, so you just need plain text to train your own model.
98
+ You can train text generation models to generate a wide variety of documents, from code to stories.
99
  </p>
100
 
101
  <h3>Text-to-Text Generation Models</h3>
102
  <p>
103
+ These models are trained to learn the mapping between a pair of texts (e.g. translation from one language to another).
104
+ The most popular variants of these models are NLLB, FLAN-T5, and BART.
105
+ Text-to-Text models are trained with multi-tasking capabilities, they can accomplish a wide range of tasks, including summarization, translation, and text classification.
106
+ </p>
107
+
108
+ <h3>Language Model Variants</h3>
109
+ When it comes to text generation, the underlying language model can come in several types:
110
+
111
+ <ul>
112
+ <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.
113
+
114
+ <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.
115
+
116
+ <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.
117
+ </ul>
118
+
119
+ <h2>Text Generation from Image and Text</h2>
120
+
121
+ <p>
122
+ There are language models that can input both text and image and output text, called vision language models.
123
+ IDEFICS 2 and MiniCPM Llama3 V are good examples.
124
+ They accept the same generation parameters as other language models.
125
+ However, since they also take images as input, you have to use them with the image-to-text pipeline.
126
+ You can find more information about this in the image-to-text task page.
127
  </p>
128
 
129
  <h2>Inference</h2>
 
131
  You can use the 🤗 Transformers library <code>text-generation</code> pipeline to do inference
132
  with text generation models. It takes an input text and generates a continuation of that text.
133
  </p>
134
+
135
  <pre style="background: #f5f5f5; padding: 15px; border-radius: 5px; overflow-x: auto;">
136
  from transformers import pipeline
137
 
 
139
  generator("Hello, I'm a language model,", max_length=30, num_return_sequences=3)
140
  </pre>
141
 
142
+ <h2>Text Generation Inference</h2>
143
+ <p>
144
+ Text Generation Inference (TGI) is an open-source toolkit for serving LLMs tackling challenges such as response time.
145
+ TGI powers inference solutions like Inference Endpoints and Hugging Chat, as well as multiple community projects.
146
+ You can use it to deploy any supported open-source large language model of your choice.
147
+ </p>
148
+
149
+ <h2>ChatUI Spaces</h2>
150
+ <p>
151
+ Hugging Face Spaces includes templates to easily deploy your own instance of a specific application.
152
+ ChatUI is an open-source interface that enables serving conversational interface for large language models and can be deployed with few clicks at Spaces.
153
+ TGI powers these Spaces under the hood for faster inference.
154
+ Thanks to the template, you can deploy your own instance based on a large language model with only a few clicks and customize it. Learn more about it here and create your large language model instance here.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  </div>
156
  """
157