Skip to content

Commit

Permalink
Merge branch 'huggingface:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ArsalaBangash authored Nov 28, 2023
2 parents 2effd65 + 30a3f6b commit 022201c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
10 changes: 10 additions & 0 deletions packages/tasks/src/tasks/text-generation/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ The most popular models for this task are GPT-based models, [Mistral](mistralai/

These models are trained to learn the mapping between a pair of texts (e.g. translation from one language to another). The most popular variants of these models are [NLLB](facebook/nllb-200-distilled-600M), [FLAN-T5](https://huggingface.co/google/flan-t5-xxl), and [BART](https://huggingface.co/docs/transformers/model_doc/bart). Text-to-Text models are trained with multi-tasking capabilities, they can accomplish a wide range of tasks, including summarization, translation, and text classification.

## Language Model Variants

When it comes to text generation, the underlying language model can come in several types:

- **Base models:** refers to plain language models like [Mistral 7B](mistralai/Mistral-7B-v0.1) and [Llama-2-70b](https://huggingface.co/meta-llama/Llama-2-70b-hf). These models are good for fine-tuning and few-shot prompting.

- **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 [Flan-T5](https://huggingface.co/google/flan-t5-xl), [Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1), and [falcon-40b-instruct](https://huggingface.co/tiiuae/falcon-40b-instruct) are examples of instruction-trained models. In general, instruction-trained models will produce better responses to instructions than base models.

- **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](https://arxiv.org/abs/2112.00861). 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](https://huggingface.co/blog/rlhf), or RLHF for short. [Llama2-Chat](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf) is an open-source model aligned through human feedback.

## Inference

You can use the 🤗 Transformers library `text-generation` pipeline to do inference with Text Generation models. It takes an incomplete text and returns multiple outputs with which the text can be completed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ from-yellow-400 to-yellow-200 dark:from-yellow-400 dark:to-yellow-600
type LabelField = "label" | "answer";
export let labelField: LabelField = "label";
export let output: Array<
{ label: string; score: number; color?: string } | { answer: string; score: number; color?: string }
{ label: string; score?: number; color?: string } | { answer: string; score?: number; color?: string }
> = [];
export let highlightIndex = -1;
export let mouseover: (index: number) => void = () => {};
export let mouseout: () => void = () => {};
$: scoreMax = Math.max(0, ...output.map((x) => x.score));
$: scoreMax = Math.max(0, ...output.map((x) => x.score ?? 0));
function text(outputItem: (typeof output)[0]) {
if (labelField in outputItem) {
Expand Down Expand Up @@ -54,11 +54,13 @@ from-yellow-400 to-yellow-200 dark:from-yellow-400 dark:to-yellow-600
to-{color ?? defaultBarColor}-200
dark:from-{color ?? defaultBarColor}-400
dark:to-{color ?? defaultBarColor}-600"
style={`width: ${Math.ceil((score / scoreMax) * 100 * 0.8)}%;`}
style={`width: ${score ? Math.ceil((score / scoreMax) * 100 * 0.8) : 0}%;`}
/>
<span class="leading-snug">{text(output[index])}</span>
</div>
<span class="pl-2">{score.toFixed(3)}</span>
{#if typeof score === "number"}
<span class="pl-2">{score.toFixed(3)}</span>
{/if}
</div>
{/each}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
isLoading: false,
estimatedTime: 0,
};
let output: Array<{ answer: string; score: number }> | null = [];
let output: Array<{ answer: string; score?: number }> | null = [];
let outputJson: string;
let question = "";
let imgSrc = "";
Expand Down Expand Up @@ -55,15 +55,18 @@
});
}
function isValidOutput(arg: any): arg is { answer: string; score: number }[] {
return Array.isArray(arg) && arg.every((x) => typeof x.answer === "string" && typeof x.score === "number");
function isValidOutput(arg: any): arg is { answer: string; score?: number }[] {
return (
Array.isArray(arg) &&
arg.every((x) => typeof x.answer === "string" && (typeof x.score === "number" || x.score === undefined))
);
}
function parseOutput(body: unknown): Array<{ answer: string; score: number }> {
function parseOutput(body: unknown): Array<{ answer: string; score?: number }> {
if (isValidOutput(body)) {
return body;
}
throw new TypeError("Invalid output: output must be of type Array<answer: string, score:number>");
throw new TypeError("Invalid output: output must be of type Array<{ answer: string, score?: number }>");
}
async function applyInputSample(sample: WidgetExampleAssetAndTextInput, opts: ExampleRunOpts = {}) {
Expand Down

0 comments on commit 022201c

Please sign in to comment.