Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations #276

Merged
merged 44 commits into from
Sep 8, 2023
Merged

Optimizations #276

merged 44 commits into from
Sep 8, 2023

Conversation

xenova
Copy link
Collaborator

@xenova xenova commented Sep 3, 2023

  • Refactoring PretrainedModel
  • New model support:
    • Camembert (models):

      let pipe = await pipeline('token-classification', 'Xenova/camembert-ner-with-dates');
      let output = await pipe("Je m'appelle jean-baptiste et j'habite à montréal depuis fevr 2012");
      // [
      //   { entity: 'I-PER', score: 0.9258053302764893, index: 5, word: 'jean' },
      //   { entity: 'I-PER', score: 0.9048717617988586, index: 6, word: '-' },
      //   { entity: 'I-PER', score: 0.9227054119110107, index: 7, word: 'ba' },
      //   { entity: 'I-PER', score: 0.9385354518890381, index: 8, word: 'pt' },
      //   { entity: 'I-PER', score: 0.9139659404754639, index: 9, word: 'iste' },
      //   { entity: 'I-LOC', score: 0.9877734780311584, index: 15, word: 'montré' },
      //   { entity: 'I-LOC', score: 0.9891639351844788, index: 16, word: 'al' },
      //   { entity: 'I-DATE', score: 0.9858269691467285, index: 18, word: 'fe' },
      //   { entity: 'I-DATE', score: 0.9780661463737488, index: 19, word: 'vr' },
      //   { entity: 'I-DATE', score: 0.980688214302063, index: 20, word: '2012' }
      // ]

      image

    • GPT-J (models):

      import { pipeline } from '@xenova/transformers';
      
      const generator = await pipeline('text-generation', 'Xenova/J-350M');
      const prompt = 'def fib(n):'
      const output = await generator(prompt, {
        max_new_tokens: 50,
      })
      // {
      //   generated_text: 'def fib(n):\n' +
      //     '    if n == 0:\n' +
      //     '        return 1\n' +
      //     '    elif n == 1:\n' +
      //     '        return fib(n - 1)\n' +
      //     '    else:\n' +
      //     '        return fib(n - 1) * fib(n - 2)\n' +
      //     '\n'
      // }
    • WavLM (Closes [Question] WavLM support  #75). (models)

      import { AutoProcessor, AutoModel, read_audio } from '@xenova/transformers';
      
      // Read and preprocess audio
      const processor = await AutoProcessor.from_pretrained('Xenova/wavlm-base');
      const audio = await read_audio('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav', 16000);
      const inputs = await processor(audio);
      
      // Run model with inputs
      const model = await AutoModel.from_pretrained('Xenova/wavlm-base');
      const output = await model(inputs);
      // {
      //   last_hidden_state: Tensor {
      //     dims: [ 1, 549, 768 ],
      //     type: 'float32',
      //     data: Float32Array(421632) [-0.349443256855011, -0.39341306686401367,  0.022836603224277496, ...],
      //     size: 421632
      //   }
      // }
    • MBart (+MBart50). See here for the full list of languages and their corresponding codes. (models)

      let translator = await pipeline('translation', 'Xenova/mbart-large-50-many-to-many-mmt');
      let output = await translator('संयुक्त राष्ट्र के प्रमुख का कहना है कि सीरिया में कोई सैन्य समाधान नहीं है', {
        src_lang: 'hi_IN', // Hindi
        tgt_lang: 'fr_XX', // French
      });
      // [{ translation_text: 'Le chef des Nations affirme qu 'il n 'y a military solution in Syria.' }]
    • OPT (models):

      const generator = await pipeline('text-generation', 'Xenova/opt-125m', {
          quantized: false, // NOTE: quantized models are currently broken
      });
      const prompt = 'Once upon a';
      const output = await generator(prompt);
      // [{ generated_text: 'Once upon a time, I was a student at the University of California, Berkeley. I was' }]
    • BeiT (models):

      let url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg';
      let pipe = await pipeline('image-classification', 'Xenova/beit-base-patch16-224');
      let output = await pipe(url);
      // [{ label: 'tiger, Panthera tigris', score: 0.7168469429016113 }]
    • ResNet (models):

      let url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/tiger.jpg';
      let pipe = await pipeline('image-classification', 'Xenova/resnet-50');
      let output = await pipe(url);
      // [{ label: 'tiger, Panthera tigris', score: 0.7576608061790466 }]

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 3, 2023

The documentation is not available anymore as the PR was closed or merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Model type for tt/ee not found, assuming encoder-only architecture [Question] WavLM support
2 participants