Commit Graph

144 Commits

Author SHA1 Message Date
Joshua Lochner db9250b3e8
Add sequence post processor (#771)
* Add `Sequence` PostProcessor

Required by https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct/

* Support `return_token_type_ids`

* Add llama3 tokenizer to unit tests

* Add test for allowing user to request for token type ids

* Add JSDoc

* Update generate_tests.py
2024-05-23 11:42:24 +02:00
Hans 880cd3ea65
Support reading data from blob URI (#645)
* Make blob as valid URL

* Create function to detect the blob URI

* Change to `isValidUrl`

* Remove comment

Co-authored-by: Joshua Lochner <admin@xenova.com>

* Merge `isValidHttpUrl` into `isValidUrl`

* Correct implement

* Update docs

* Add test

* Remove export for `isValidUrl`

* Test read blob via `getFile`

* Use `res.text()` instead `res.body`

---------

Co-authored-by: Joshua Lochner <admin@xenova.com>
2024-05-08 13:14:50 +02:00
Joshua Lochner 7122a0a5a1
Add mobilevitv2 (#721)
* Add support for MobileViTV2

* Update supported_models.py

* Add support for `do_flip_channel_order`

* Add unit test for `do_flip_channel_order=true`
2024-05-02 11:42:44 +02:00
Joshua Lochner 1a9964fb09
Use ungated version of mistral tokenizer (#718) 2024-04-20 16:01:17 +02:00
Joshua Lochner c2c45cb577
Improve support of conversational models (#658)
* Add `return_full_text` option for text-generation models

* [wip] Support chat inputs in text-generation pipeline

* Align return type with python version

* Remove conversational task (moved to text-generation)

* Fix typos
2024-04-11 00:58:50 +02:00
Joshua Lochner f0ef2e8eee
Update tokenizer `apply_chat_template` functionality (#647)
* Allow custom kwargs in `tokenizer.apply_chat_template`

* Update jinja dependency version

* Add `tokenizer_kwargs` options

* Add support for dictionaries of chat templates in the tokenizer config

* Add `CohereTokenizer`

* `apply_chat_template` is no longer async

* Add unit test for multiple chat templates

* Update tokenizers.js

* Also update when `chat_template` is undefined

* Support setting tokenizer and text from URL

* Update Claude tokenizer display name

* Add Cohere Command-R tokenizer to playground

* Add `Grok1Tokenizer`

* Throw error if chat template object is malformed

* Improved error checking

* Remove redundant error check

* `template_dict` can be a null-prototype object
2024-03-20 15:22:01 +02:00
Joshua Lochner 40cdd36597
Fix channel format when padding non-square images for certain models (#655)
* Add tensor permute unit tests

* Rename transpose -> permute

* Fix padding for non-square images

* Add vitmatte padding unit test

* Create `RawImage.toTensor` helper function

* Add bankers rounding test case

* `.toBe()` -> `.toBeCloseTo()` for floating point numbers
2024-03-20 14:35:30 +02:00
Joshua Lochner a51a61be22
Add support for EfficientNet (#639)
* Add support for efficientnet

* Add `EfficientNetImageProcessor`
2024-03-16 14:49:32 +02:00
Joshua Lochner dab1b8139f
Remove GH-specific redirect logic (#630) 2024-03-07 02:47:32 +02:00
Joshua Lochner 68ed7f6cbb
Add Gemma Tokenizer (#598)
* Fix styling for whitespace tokens

* Add `GemmaTokenizer`

* Update minimum `@huggingface/jinja` version

* Add Gemma to tokenizer playground

* Add Gemma tokenizer unit test

* Update tokenizer names in playground

* Update Gemma tokenizer test
2024-02-21 16:22:22 +02:00
Joshua Lochner e9092d2337
Add basic 2D `layer_norm` operator (#588) 2024-02-19 14:53:06 +02:00
Joshua Lochner ae7af0a6c2
Add support for Qwen2 models (#570)
* Add support for `Qwen2Tokenizer`

* Add qwen-specific tokenizer unit test

* Add support for qwen2 models

* Fix typo
2024-02-06 12:44:30 +02:00
Joshua Lochner b1f96a2fc9
Add support for wav2vec2-bert (#544)
* Add povey window function

* Add `SeamlessM4TFeatureExtractor`

* Add support for wav2vec2-bert models

* Add `SeamlessM4TFeatureExtractor` processor unit tests

* Add pipeline support for `wav2vec2-bert` models

* Update JSDoc
2024-01-27 17:50:03 +02:00
Joshua Lochner 03f2763a27
Add whitespace pretokenizer (#542)
* Add `WhitespacePreTokenizer`

* Add unit test for `Whitespace` pretokenizer
2024-01-27 15:13:20 +02:00
Joshua Lochner 587adfc193
Add support for Depth Anything (#534)
* Add support for `DPTImageProcessor`

* Add support for depth anything model

* Update list of `depth_anything` models

* Update processor test model id
2024-01-25 15:21:51 +02:00
Joshua Lochner cdcbfc125c
Add support for Segment Anything Model (#510)
* Update SamModel

* Make `AutoModel.from_pretrained` work with SamModel

* Add listed support for SAM (Segment Anything Model)

* Update types of `calculateDimensions`

* Throw error if reading image from tensor with dims.length != 3

* Make SamProcessor input points optional

* Fix type errors

* `let` -> `const`

* `cat` -> `stack`

* Expose `reshape_input_points` in `SamProcessor`

* Add `input_labels` input parameter for SAM

* Add `input_labels` to sam processor

* Update SAM unit tests

* Remove TODOs

* Update JSDoc
2024-01-10 17:47:21 +02:00
Joshua Lochner 4d1d4d3346
Add support for processing non-square images w/ `ConvNextFeatureExtractor` (#503)
* Abstract resize function

* Fix tolerance comparison

* Update `ConvNextFeatureExtractor`

* Update ConvNext unit test
2024-01-10 17:04:21 +02:00
Joshua Lochner ebd533531a
Add support for cross-encoder models (+fix token type ids) (#501)
* Formatting

* Update ESM pair template

* Fix token type ids

* Update JSDoc

* Cleanup

* Remove unused `prepare_model_inputs` function

* Move pad and truncate logic to helper functions

* Add static padding/truncation unit tests

* Fix padding/truncation

* Remove unused `add_token_types` function

* Reduce duplication

* `let` -> `const` where possible

* Add cross-encoder models
2024-01-04 18:37:26 +02:00
Joshua Lochner e2d17b946f
Add support for SigLIP models (#473)
* Add support for SigLIP models

* Skip siglip tokenizer tests

* Move SigLIP-specific zero-shot-image-classification logic to pipeline
2023-12-27 15:49:33 +02:00
Joshua Lochner 80af1c49bb
Add support for Segformer (#480)
* Add support for Segformer

* Add semantic segmentation unit test

* Update pipelines.test.js
2023-12-27 15:12:07 +02:00
Joshua Lochner 1394f73107
Add support for VITS (multilingual TTS) (#466)
* Add custom VITS tokenizer converter

* Do not decode if expected input_ids is empty

* Update vits tokenizer tests

* Implement `VitsTokenizer`

* Add support for VITS model

* Support VITS through pipeline API

* Update JSDoc

* Add TTS unit test

* Add speecht5 unit test

* Fix typo

* Fix typo

* Update speecht5 model id

* Add note about using quantized speecht5 in unit tests

* Monkey-patch `BigInt64Array` and `BigUint64Array`
2023-12-26 16:34:52 +02:00
Joshua Lochner c91248cf70
Add support for RoFormer models (#464)
* Add `RoFormerTokenizer

* Use `clean_text` in bert normalizer config

* Add control characters test

* Add support for RoFormer models

* Use default label if id2label is not specified

* Update requirements.txt

* Skip roformer tokenizer tests
2023-12-26 15:49:11 +02:00
Joshua Lochner 1427125dc3
Update jinja dependency (#459)
* Make `@huggingface/jinja` a dependency

* Update package-lock.json

* Update JSDoc
2023-12-18 23:22:24 +02:00
Joshua Lochner d4f7cd5024
Add support for chat templates (#408)
* Add basic support for chat templates

* Cleanup

* JSDoc improvements

* Support conversion of user-defined functions

* Cleanup

* Fix function creation

* Add unit tests for templates

* Cleanup

* Improve JSDoc

* Add missing return types

* Add chat templates docs to table of contents

* Add support for logical negation

* Fix nested logical negation

* Add unit tests for logical operators

* Add loop variables

* Add support for `RuntimeValue` built-in functions

* Add unit tests for string instance methods

* Fix conversion of normal function to `FunctionValue`

* Update object method unit tests

* Save chat template to tokenizer_config.json during conversion

* Fix `raise_exception` error

* Add `!=` operator for booleans

* Remember to increment loop index

* Cleanup for loop evaluator

* Use `is` helper function

* Add support for text nodes

i.e., non Jinja statements/expressions

* Add auto-generated templating tests

* Update unit tests

* Remove unused function

* Add default chat templates

* Use repo with up-to-date tokenizer config

* Temporarily disable zephyr test

* Delete templates.test.js

* Move Jinja functionality to `@huggingface/jinja`

* Fix template cache type

* Update chat template unit tests

* Update `@huggingface/jinja` version

* Fix default llama2 system prompt usage

* Add unit test for llama2 w/o chat template set

* Update jinja version

* Update jinja version

* Add unit test for user-defined chat templates

Example from https://discuss.huggingface.co/t/issue-with-llama-2-chat-template-and-out-of-date-documentation/61645/3

* Add `AddedToken` for improved tokenization

* Add example usage for chat templates

* Add 'first' Metaspace pretokenizer prepend scheme

* Formatting

* Update wav2vec2 converter special tokens whitespace split

* Fix Metaspace pretokenizer split criteria

* Update inputs of `PreTokenizerSequence`

* Improve Metaspace pretokenizer

* Update llama tokenizer tests

* Improve handling of legacy llama tokenizer

* Re-enable SPM tests

* Add static tokenizer test cases

* Add llama2 static tests

* Allow user to override legacy tokenizer behaviour in `.from_pretrained`

* Add legacy tokenizer unit tests

* Bump jinja version to 0.1.0
2023-12-18 17:00:50 +02:00
Joshua Lochner 2de085b6e5
Add support for ChineseCLIP models (#455)
* Update `VitMatteImageProcessor` test comment

* Add support for ChineseCLIP models

* Add chinese-clip to list of supported models

* Sort zero-shot-image-classification results by score (desc)

* Update expected zero-shot image classification output
2023-12-13 14:47:17 +02:00
Joshua Lochner b978ff8ce4
Add support for ViTMatte models (#448)
* Add support for `VitMatte` models

* Add `VitMatteImageProcessor`

* Add `VitMatteImageProcessor` unit test

* Fix typo

* Add example code for `VitMatteForImageMatting`

* Fix JSDoc

* Fix typo
2023-12-13 02:18:36 +02:00
Joshua Lochner 80d22dae7b
Add support for ESM models (#447)
* Add support for ESM models

* Add ESM tokenizer conversion methods

* Add special test cases for ESM tokenizer

* add special tokens in conversion script

* Do not save decoder

* Add special tokens tokenizer test

* Join tokens with space if decoder is null

* Treat all tokens as added tokens

* Use `WhitespaceSplit` pretokenizer

* `<eos>` and `<bos>` are not special tokens

* Update more supported ESM models

* Add `--tokenizer_id` to conversion script

* Add supported models comments
2023-12-13 02:10:27 +02:00
Joshua Lochner 9308f880c5
Add support for DINOv2 models (#444)
* Add dinov2 models

* Add `BitImageProcessor`

* Update list of supported models
2023-12-12 17:42:48 +02:00
Joshua Lochner 9a8c664c2c
Documentation improvements (#299)
* Add link to optimum docs for supported architectures

Closes #288

* Refactor `SUPPORTED_MODELS` dict to include task

* Update example model id

* Update list of supported models

* Update generate_tests.py

* Remove requirement of `output_attentions` revision

* Add demo site to examples section (closes #233)

* Fix typo

* Include examples in docs index

* Update github issue templates

* Create config.yml

* Order supported models

* Cleanup

* Update 4_feature-request.yml
2023-12-06 17:01:36 +02:00
Joshua Lochner b1a4b58e86 Update processor unit test's max execution time 2023-12-05 12:37:51 +02:00
Joshua Lochner c5ed1d70ca
Add support for CLAP (`zero-shot-audio-classification`) and Audio Spectrogram Transformer (`audio-classification`) (#427)
* Add FFT unit tests

* Refactor maths.js and audio.js

* Refactor audio processors

* Add support for AST models

* Add another audio-classification example

* Add audio processing unit tests

* Implement `log_mel='dB'` in `spectrogram` function

* Add `ClapFeatureExtractor`

* Implement `ClapFeatureExtractor` unit tests

* Add support for `CLAP`

* Add `ZeroShotAudioClassificationPipeline`

* Add listed support for  `zero-shot-audio-classification` pipeline tag

* Cleanup

* `let` -> `const`

* Update `mel_filter_bank` unit test

* Add `'Xenova/tiny-random-ClapModel'`

* Add `ClapAudioModelWithProjection` and `ClapTextModelWithProjection`

* Move audio validation to helper function

* Optimize `mel_filter_bank` computation

-30ms

* Update mel filters unit test

* Cleanup

* Optimizations

* Fix jsdoc

* Optimizations

* Add WIP conversion scripts

Will be updated once https://github.com/huggingface/optimum/pull/1552 is merged
2023-12-05 12:17:42 +02:00
Joshua Lochner 3da3841811
Support decoding of tensors (#416)
* Support decoding of tensors (Closes #362)

* Remove debug line
2023-12-02 16:17:57 +02:00
Joshua Lochner 83dfa4718e
Add `depth-estimation` w/ DPT and GLPN (#389)
* Add `size` getter to `RawImage`

* Add `DPTFeatureExtractor`

* Add depth-estimation w/ DPT models

* Add GLPN models for depth estimation

* Add missing import in example

* Add `DPTFeatureExtractor` processor test

* Add unit test for GLPN processor

* Add support for `GLPNFeatureExtractor`

Uses `size_divisor` to determine resize width and height

* Add `GLPNForDepthEstimation` example code

* Add DPT to list of supported models

* Add GLPN to list of supported models

* Add `DepthEstimationPipeline`

* Add listed support for depth estimation pipeline

* Add depth estimation pipeline unit tests

* Fix formatting

* Update `pipeline` JSDoc

* Fix typo from merge
2023-11-20 15:43:45 +02:00
Joshua Lochner 5ddc4722f3
Add support for nougat models (`image-to-text`) (#391)
* Add `NougatTokenizer`

* Add nougat unit tests

* Add support for `NougatImageProcessor`

* Add `crop` function to `RawImage`

* Fix `RawImage` save function

OffscreenCanvas does not have `toDataURL` function

* Add listed support for nougat models

* Fix `min`/`max` function typing

* Add unknown token to tokenizer class

* Implement `NoBadWordsLogitsProcessor`

* Use `NoBadWordsLogitsProcessor` in `generate`

* Fix regex group substitutions

Python uses \1, \2, etc. for group substitutions, but JavaScript uses $1, $2, etc.

* Create `regexSplit` helper function to split but keep delimiter

* Fix splitting for String pattern types

* Fix docstring
2023-11-20 15:14:11 +02:00
Joshua Lochner 7cf8a2c442
Add `zero-shot-object-detection` w/ OwlViT (#392)
* Set `batch_size=1` for owlvit exports

* Add support for owlvit models

* Update default quantization settings

* Add list of supported models

* Revert update of owlvit quantization settings

* Add `OwlViTProcessor`

* Move `get_bounding_box` to utils

* Add `ZeroShotObjectDetectionPipeline`

* Add unit tests

* Add owlvit processor test

* Add listed support for `zero-shot-object-detection`

* Add OWL-ViT to list of supported models

* Update README.md

* Fix typo from merge
2023-11-20 14:34:56 +02:00
Joshua Lochner b8719b12dd
Ensure WASM fallback does not crash in GH actions (#402)
* Ensure WASM fallback does not crash in GH actions

* Add unit test for WordPiece `max_input_chars_per_word`

* Cleanup

* Set max test concurrency to 1
2023-11-19 08:06:49 +02:00
Joshua Lochner 35d61f5cc9
Add `CLIPFeatureExtractor` (and tests) (#387) 2023-11-15 16:28:29 +02:00
Joshua Lochner 73a99ba0af
Add image-to-image task w/ Swin2SR (for super-resolution) (#381)
* Add `Swin2SRImageProcessor`

* Add `RawImage.fromTensor` helper function

* Add clamp tensor function

* Add support for `.to` data type conversion

* Add `round` tensor function

* Add support for `mul` tensor function

* Fix image padding

* Only perform padding if it will affect size

* Create basic processors unit test suite

* Add SamProcessor test case

* Move `CONTENT_TYPE_MAP` outside `RawImage` class

* Perform reflective padding for swin2sr models

* Add swin2sr models for image super-resolution

* Add listed support for Swin2SR models

* Add image-to-image pipeline

* Add listed support for image-to-image task

* Add image-to-image unit tests

* Add `add` tensor functions

* Generalize `pad_image` helper function

* Add more unit tests for image processors

* Fix typo
2023-11-09 17:57:32 +02:00
Joshua Lochner 96c5dd4ccf
Fix `text2text-generation` pipeline output inconsistency w/ python library (#384)
* Fix `text2text-generation` pipeline inconsistency

See https://huggingface.co/docs/transformers/v4.35.0/en/main_classes/pipelines#transformers.Text2TextGenerationPipeline

* Fix `text2text-generation` example in docs

* Improve text2text-generation output in docs
2023-11-09 16:08:27 +02:00
Joshua Lochner 4a991bd911
Add support for `text-to-speech` (w/ Speecht5) (#345)
* Add vocoder to export

* Add tokenizer.json export for speecht5 models

* Update speecht5 supported models

* Create `SpeechT5Tokenizer`

* Add `ones` and `ones_like` tensor functions

* Add support for speecht5 text-to-speech

* Disambiguate `SpeechSeq2Seq` and `Seq2SeqLM`

* Create `TextToAudioPipeline`

* Add listed support for `text-to-audio` / `text-to-speech`

* Use unquantized vocoder by default

* Skip speecht5 unit tests for now

Due to bug in transformers: https://github.com/huggingface/transformers/issues/26547

* Update example pipeline output

* Create simple in-browser TTS demo

* Add template README

* Delete package-lock.json

* Update required transformers.js version

* Add link to Transformers.js

* Double -> Single quotes

* Add link to text-to-speech demo

* Update sample speaker embeddings
2023-10-23 16:31:46 +02:00
Joshua Lochner b6bd608322
Update falcon tokenizer (#344)
* Update generate_tests.py

* Do not add token types for `FalconTokenizer`
2023-10-03 12:35:07 +02:00
Joshua Lochner d307f270dd
Add support for `DonutSwin` models (#320)
* Add `add_special_tokens` option to tokenizers

* Improve error messages for loading processors

* Add `DonutFeatureExtractor`

* Add `DonutSwinModel` and `MBartForCausalLM` models

* Fix `addPastKeyValues` for `VisionEncoderDecoder` models

* Add `Donut` to list of supported models

* Make encode parameters optional

* Support batched decoder input ids

* Remove unused import

* Add `do_thumbnail` for donut image processing

* Fix `TypeError: decoder_input_ids[i].map is not a function`

* Only pad if width and height specified in size

* Only pad if `pad_size` is defined

* Only cut `decoder_input_ids` if past model output

* Add donut model

* Add example usage to JSDoc for `DonutSwinModel`

* Add support for `DocumentQuestionAnsweringPipeline`

* Add simple document question answering unit test

* Add listed support for document QA pipeline
2023-09-26 17:46:26 +02:00
Joshua Lochner c367f9d68b
Add support for `Blenderbot` and `BlenderbotSmall` (#292)
* Add support for `Blenderbot` models

Closes #37
References #29

* Add support for `BlenderbotTokenizer`

* Add blenderbot to supported models

* Add support for `BlenderbotSmallTokenizer`

* Add custom tests for blenderbot-small

* Add support for `BlenderbotSmall` models

* Update list of supported models

* Improve `addPastKeyValues` function

* Allow skipping of adding encoder past key values
2023-09-19 13:34:00 +02:00
Joshua Lochner 11f6a08090
Add support for `min_length` and `min_new_tokens` generation parameters (#308)
* Add support for `MinNewTokensLengthLogitsProcessor`

* Add support for `MinLengthLogitsProcessor`

* Fix `generation_config` defaults

* Fix `input_ids_seq_length`

* Add unit tests for generation

* Fix generation parameters test case

* Allow specification of multiple `eos_token_ids`
2023-09-17 23:57:13 +02:00
Joshua Lochner 5216fb461d
Fix `ByteLevel` pretokenizer
* Re-enable other whisper tests

* Fix `ByteLevel` pretokenizer

Only add prefix space to first word, when option is enabled.
2023-09-10 00:37:04 +02:00
Joshua Lochner 9a3339239e
New models and refactoring (#276)
* Add `CodeLlamaTokenizer`

* Add `codellama` for testing

* Update default quantization settings

* Refactor `PretrainedModel`

* Remove unnecessary error message

* Update llama-code-tokenizer test

* Add support for `GPTNeoX` models

* Fix `GPTNeoXPreTrainedModel` config

* Add support for `GPTJ` models

* Add support for `WavLM` models

* Update list of supported models

- CodeLlama
- GPT NeoX
- GPT-J
- WavLM

* Add support for XLM models

* Add support for `ResNet` models

* Add support for `BeiT` models

* Fix casing of `BeitModel`

* Remove duplicate code

* Update variable name

* Remove `ts-ignore`

* Remove unnecessary duplication

* Update demo model sizes

* [demo] Update default summarization parameters

* Update default quantization parameters for new models

* Remove duplication in mapping

* Update list of supported marian models

* Add support for `CamemBERT` models

* Add support for `MBart` models

* Add support for `OPT` models

* Add `MBartTokenizer` and `MBart50Tokenizer`

* Add example of multilingual translation with MBart models

* Add `CamembertTokenizer`

* Add support for `HerBERT` models

* Add support for `XLMTokenizer`

* Fix `fuse_unk` config

* Do not remove duplicate keys for `Unigram` models

See https://huggingface.co/camembert-base for an example of a Unigram tokenizer that has two tokens with the same value (`<unk>`)

* Update HerBERT supported model text

* Update generate_tests.py

* Update list of supported models

* Use enum object instead of classes for model types

Fixes https://github.com/xenova/transformers.js/issues/283

* Add link to issue

* Update dependencies for unit tests

* Add `sentencepiece` as a testing requirement

* Add `protobuf` to test dependency

* Remove duplicated models to test
2023-09-08 15:17:05 +02:00
Joshua Lochner 109a7f9711 Fix unit test 2023-09-04 23:53:05 +02:00
Joshua Lochner 96b9143b33 Update masked-lm tests 2023-09-02 03:47:06 +02:00
Joshua Lochner 3fab8265cb
Update whisper unit test (#258) 2023-08-22 22:18:17 +02:00
Joshua Lochner c3af596443
Fix word-level timestamps for non-English languages w/ Whisper (#253)
* Fix language detection

* Remove debug statement

* Fix punctuation regex for whisper decoding (Closes #223)

* Fix word-level timestamps for audio < 30 seconds

Issue in python library: https://github.com/huggingface/transformers/issues/25605
PR for above: https://github.com/huggingface/transformers/pull/25607

* Add multilingual transcription w/ word-level timestamps unit test

* Fix unit tests
2023-08-22 15:50:30 +02:00