Skip to content

Commit 802e164

Browse files
Wauplinxenovajulien-cSBrandeis
authored
Update conversational widget to use text-generation (+ remove conversational task) (#457)
Done as part of huggingface-internal/moon-landing#8578. Should be merged before (or at the same time) as huggingface-internal/moon-landing#8723. This is only a first draft to check if we have everything we need. From huggingface-internal/moon-landing#8578: > In huggingface.js and api-inference > - [ ] Models that are secondary tagged as `conversational` will get the `ConversationalWidget` > - [ ] The `ConversationalWidget` will call the `text-generation` API under the hood. The widget needs to take care of all prompt formatting (using the recent jinja work in `huggingface.js`) > - [ ] Should we just kill the conversational API in the inference API with the APIs unification? > This would break use cases such as `pipeline("microsoft/DialoGPT-medium")` in `transformers` > > Result: > * All models with conversational capabilities will have a nice widget > * We eliminate the fragmentation of tasks (conversational vs text generation) > * We remove the confusing conv pipeline Currently in this PR: - ✔️ _Models that are secondary tagged as conversational will get the ConversationalWidget_ - ✔️ _The `ConversationalWidget` will call the `text-generation` API under the hood._ (automatic in inference API if `pipeline_tag` gets updated by huggingface-internal/moon-landing#8723) - ✔️ _The widget needs to take care of all prompt formatting_ (not complete) cc @xenova @osanseviero @SBrandeis @coyotte508 --- Still unsure how to proceed: - how to handle the transition period? => **EDIT:** no transition period - what to do if we don't have a `chat_template`? => **EDIT:** raise error - what if we have a `chat_template` but no `eos_token` / `bos_token`? => **EDIT:** should be ok - should we keep the `Conversation` structure in the widget (with `generated_responses` / `past_user_inputs` / `generated_text`) ? If not, would need more svelte expertise 😄 => **EDIT:** ok --------- Co-authored-by: Joshua Lochner <[email protected]> Co-authored-by: Julien Chaumond <[email protected]> Co-authored-by: Simon Brandeis <[email protected]>
1 parent 705588e commit 802e164

File tree

24 files changed

+176
-323
lines changed

24 files changed

+176
-323
lines changed

packages/inference/src/tasks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export * from "./cv/imageToImage";
1818
export * from "./cv/zeroShotImageClassification";
1919

2020
// Natural Language Processing tasks
21-
export * from "./nlp/conversational";
2221
export * from "./nlp/featureExtraction";
2322
export * from "./nlp/fillMask";
2423
export * from "./nlp/questionAnswering";

packages/inference/src/tasks/nlp/conversational.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

packages/inference/test/HfInference.spec.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -333,25 +333,6 @@ describe.concurrent(
333333
])
334334
);
335335
});
336-
it("conversational", async () => {
337-
expect(
338-
await hf.conversational({
339-
model: "microsoft/DialoGPT-large",
340-
inputs: {
341-
past_user_inputs: ["Which movie is the best ?"],
342-
generated_responses: ["It is Die Hard for sure."],
343-
text: "Can you explain why ?",
344-
},
345-
})
346-
).toMatchObject({
347-
generated_text: "It's the best movie ever.",
348-
conversation: {
349-
past_user_inputs: ["Which movie is the best ?", "Can you explain why ?"],
350-
generated_responses: ["It is Die Hard for sure.", "It's the best movie ever."],
351-
},
352-
warnings: ["Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation."],
353-
});
354-
});
355336
it("SentenceSimilarity", async () => {
356337
expect(
357338
await hf.sentenceSimilarity({

packages/tasks/src/default-widget-inputs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { WidgetExample } from "./widget-example";
2-
import type { PipelineType } from "./pipelines";
2+
import type { WidgetType } from "./pipelines";
33

44
type LanguageCode = string;
55

6-
type PerLanguageMapping = Map<PipelineType, string[] | WidgetExample[]>;
6+
type PerLanguageMapping = Map<WidgetType, string[] | WidgetExample[]>;
77

88
/// NOTE TO CONTRIBUTORS:
99
///

packages/tasks/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from "./tasks";
55
export {
66
PIPELINE_DATA,
77
PIPELINE_TYPES,
8+
type WidgetType,
89
type PipelineType,
910
type PipelineData,
1011
type Modality,
@@ -16,6 +17,7 @@ export {
1617
export { ALL_DISPLAY_MODEL_LIBRARY_KEYS, ALL_MODEL_LIBRARY_KEYS, MODEL_LIBRARIES_UI_ELEMENTS } from "./model-libraries";
1718
export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries";
1819
export type { ModelData, TransformersInfo } from "./model-data";
20+
export type { SpecialTokensMap, TokenizerConfig } from "./tokenizer-data";
1921
export type {
2022
WidgetExample,
2123
WidgetExampleAttribute,
@@ -37,6 +39,7 @@ export type {
3739
WidgetExampleOutputText,
3840
} from "./widget-example";
3941
export { InferenceDisplayability } from "./model-data";
42+
export { SPECIAL_TOKENS_ATTRIBUTES } from "./tokenizer-data";
4043

4144
import * as snippets from "./snippets";
4245
export { snippets };

packages/tasks/src/library-to-tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const LIBRARY_TASK_MAPPING_EXCLUDING_TRANSFORMERS: Partial<Record<ModelLi
2727
keras: ["image-classification"],
2828
nemo: ["automatic-speech-recognition"],
2929
open_clip: ["zero-shot-classification", "zero-shot-image-classification"],
30-
paddlenlp: ["conversational", "fill-mask", "summarization", "zero-shot-classification"],
30+
paddlenlp: ["fill-mask", "summarization", "zero-shot-classification"],
3131
peft: ["text-generation"],
3232
"pyannote-audio": ["automatic-speech-recognition"],
3333
"sentence-transformers": ["feature-extraction", "sentence-similarity"],

packages/tasks/src/model-data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PipelineType } from "./pipelines";
22
import type { WidgetExample } from "./widget-example";
3+
import type { TokenizerConfig } from "./tokenizer-data";
34

45
export enum InferenceDisplayability {
56
/**
@@ -53,6 +54,7 @@ export interface ModelData {
5354
base_model_name?: string;
5455
task_type?: string;
5556
};
57+
tokenizer?: TokenizerConfig;
5658
};
5759
/**
5860
* all the model tags

packages/tasks/src/pipelines.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,6 @@ export const PIPELINE_DATA = {
225225
modality: "nlp",
226226
color: "indigo",
227227
},
228-
conversational: {
229-
name: "Conversational",
230-
subtasks: [
231-
{
232-
type: "dialogue-generation",
233-
name: "Dialogue Generation",
234-
},
235-
],
236-
modality: "nlp",
237-
color: "green",
238-
},
239228
"feature-extraction": {
240229
name: "Feature Extraction",
241230
modality: "nlp",
@@ -248,6 +237,14 @@ export const PIPELINE_DATA = {
248237
type: "dialogue-modeling",
249238
name: "Dialogue Modeling",
250239
},
240+
{
241+
type: "dialogue-generation",
242+
name: "Dialogue Generation",
243+
},
244+
{
245+
type: "conversational",
246+
name: "Conversational",
247+
},
251248
{
252249
type: "language-modeling",
253250
name: "Language Modeling",
@@ -667,6 +664,8 @@ export const PIPELINE_DATA = {
667664

668665
export type PipelineType = keyof typeof PIPELINE_DATA;
669666

667+
export type WidgetType = PipelineType | "conversational";
668+
670669
export const PIPELINE_TYPES = Object.keys(PIPELINE_DATA) as PipelineType[];
671670

672671
export const SUBTASK_TYPES = Object.values(PIPELINE_DATA)

packages/tasks/src/snippets/curl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export const curlSnippets: Partial<Record<PipelineType, (model: ModelData, acces
3434
"zero-shot-classification": snippetZeroShotClassification,
3535
translation: snippetBasic,
3636
summarization: snippetBasic,
37-
conversational: snippetBasic,
3837
"feature-extraction": snippetBasic,
3938
"text-generation": snippetBasic,
4039
"text2text-generation": snippetBasic,

packages/tasks/src/snippets/inputs.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ const inputsTranslation = () => `"Меня зовут Вольфганг и я
99
const inputsSummarization = () =>
1010
`"The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct."`;
1111

12-
const inputsConversational = () =>
13-
`{
14-
"past_user_inputs": ["Which movie is the best ?"],
15-
"generated_responses": ["It is Die Hard for sure."],
16-
"text": "Can you explain why ?"
17-
}`;
18-
1912
const inputsTableQuestionAnswering = () =>
2013
`{
2114
"query": "How many stars does the transformers repository have?",
@@ -96,7 +89,6 @@ const modelInputSnippets: {
9689
"audio-to-audio": inputsAudioToAudio,
9790
"audio-classification": inputsAudioClassification,
9891
"automatic-speech-recognition": inputsAutomaticSpeechRecognition,
99-
conversational: inputsConversational,
10092
"document-question-answering": inputsVisualQuestionAnswering,
10193
"feature-extraction": inputsFeatureExtraction,
10294
"fill-mask": inputsFillMask,

0 commit comments

Comments
 (0)