2021-02-05 17:12:51 +00:00
|
|
|
{ lib
|
2021-12-19 01:06:50 +00:00
|
|
|
, stdenv
|
2022-06-16 17:23:12 +00:00
|
|
|
, buildPythonPackage
|
|
|
|
, datasets
|
2020-07-18 16:06:22 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchurl
|
2021-12-19 01:06:50 +00:00
|
|
|
, libiconv
|
2020-11-03 02:18:15 +00:00
|
|
|
, numpy
|
2022-06-16 17:23:12 +00:00
|
|
|
, openssl
|
|
|
|
, pkg-config
|
2020-11-03 02:18:15 +00:00
|
|
|
, pytestCheckHook
|
2022-06-16 17:23:12 +00:00
|
|
|
, pythonOlder
|
2020-07-18 16:06:22 +00:00
|
|
|
, requests
|
2022-06-16 17:23:12 +00:00
|
|
|
, rustPlatform
|
|
|
|
, Security
|
|
|
|
, setuptools-rust
|
2020-07-18 16:06:22 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2022-06-16 17:23:12 +00:00
|
|
|
# See https://github.com/huggingface/tokenizers/blob/main/bindings/python/tests/utils.py for details
|
|
|
|
# about URLs and file names
|
2020-07-18 16:06:22 +00:00
|
|
|
robertaVocab = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/roberta-base-vocab.json";
|
|
|
|
sha256 = "0m86wpkfb2gdh9x9i9ng2fvwk1rva4p0s98xw996nrjxs7166zwy";
|
|
|
|
};
|
|
|
|
robertaMerges = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/roberta-base-merges.txt";
|
|
|
|
sha256 = "1idd4rvkpqqbks51i2vjbd928inw7slij9l4r063w3y5fd3ndq8w";
|
|
|
|
};
|
2020-11-03 02:18:15 +00:00
|
|
|
albertVocab = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/albert-base-v1-tokenizer.json";
|
|
|
|
sha256 = "1hra9pn8rczx7378z88zjclw2qsdrdwq20m56sy42s2crbas6akf";
|
|
|
|
};
|
2020-07-18 16:06:22 +00:00
|
|
|
bertVocab = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased-vocab.txt";
|
|
|
|
sha256 = "18rq42cmqa8zanydsbzrb34xwy4l6cz1y900r4kls57cbhvyvv07";
|
|
|
|
};
|
2020-11-03 02:18:15 +00:00
|
|
|
norvigBig = fetchurl {
|
|
|
|
url = "https://norvig.com/big.txt";
|
|
|
|
sha256 = "0yz80icdly7na03cfpl0nfk5h3j3cam55rj486n03wph81ynq1ps";
|
|
|
|
};
|
2020-11-12 09:05:59 +00:00
|
|
|
docPipelineTokenizer = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/anthony/doc-pipeline/tokenizer.json";
|
|
|
|
hash = "sha256-i533xC8J5CDMNxBjo+p6avIM8UOcui8RmGAmK0GmfBc=";
|
|
|
|
};
|
|
|
|
docQuicktourTokenizer = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/anthony/doc-quicktour/tokenizer.json";
|
|
|
|
hash = "sha256-ipY9d5DR5nxoO6kj7rItueZ9AO5wq9+Nzr6GuEIfIBI=";
|
|
|
|
};
|
2020-07-18 16:06:22 +00:00
|
|
|
openaiVocab = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/openai-gpt-vocab.json";
|
|
|
|
sha256 = "0y40gc9bixj5rxv674br1rxmxkd3ly29p80x1596h8yywwcrpx7x";
|
|
|
|
};
|
|
|
|
openaiMerges = fetchurl {
|
|
|
|
url = "https://s3.amazonaws.com/models.huggingface.co/bert/openai-gpt-merges.txt";
|
|
|
|
sha256 = "09a754pm4djjglv3x5pkgwd6f79i2rq8ydg0f7c3q1wmwqdbba8f";
|
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
in
|
|
|
|
buildPythonPackage rec {
|
2020-07-18 16:06:22 +00:00
|
|
|
pname = "tokenizers";
|
2022-06-16 17:23:12 +00:00
|
|
|
version = "0.12.1";
|
|
|
|
|
|
|
|
disabled = pythonOlder "3.7";
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "huggingface";
|
|
|
|
repo = pname;
|
2022-06-16 17:23:12 +00:00
|
|
|
rev = "python-v${version}";
|
|
|
|
hash = "sha256-XIXKgcqa6ToAH4OkyaaJALOS9F+sD8d5Z71RttRcIsw=";
|
2020-07-18 16:06:22 +00:00
|
|
|
};
|
|
|
|
|
2021-03-09 03:18:52 +00:00
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
|
|
|
inherit src sourceRoot;
|
|
|
|
name = "${pname}-${version}";
|
2022-06-16 17:23:12 +00:00
|
|
|
sha256 = "sha256-Euvf0LNMa2Od+6gY1Ldge/7VPrH5mJoZduRRsb+lM/E=";
|
2021-03-09 03:18:52 +00:00
|
|
|
};
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
|
|
sourceRoot = "source/bindings/python";
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
setuptools-rust
|
|
|
|
] ++ (with rustPlatform; [
|
2021-03-09 03:18:52 +00:00
|
|
|
cargoSetupHook
|
|
|
|
rust.cargo
|
|
|
|
rust.rustc
|
|
|
|
]);
|
2020-07-18 16:06:22 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
buildInputs = [
|
|
|
|
openssl
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
2021-12-19 01:06:50 +00:00
|
|
|
libiconv
|
2022-06-16 17:23:12 +00:00
|
|
|
Security
|
2021-12-19 01:06:50 +00:00
|
|
|
];
|
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
propagatedBuildInputs = [
|
2020-11-03 02:18:15 +00:00
|
|
|
numpy
|
2020-07-18 16:06:22 +00:00
|
|
|
];
|
|
|
|
|
2021-05-28 09:39:13 +00:00
|
|
|
checkInputs = [
|
2021-02-05 17:12:51 +00:00
|
|
|
datasets
|
2020-11-03 02:18:15 +00:00
|
|
|
pytestCheckHook
|
|
|
|
requests
|
|
|
|
];
|
2020-07-18 16:06:22 +00:00
|
|
|
|
|
|
|
postUnpack = ''
|
2022-06-16 17:23:12 +00:00
|
|
|
# Add data files for tests, otherwise tests attempt network access
|
2020-07-18 16:06:22 +00:00
|
|
|
mkdir $sourceRoot/tests/data
|
|
|
|
( cd $sourceRoot/tests/data
|
|
|
|
ln -s ${robertaVocab} roberta-base-vocab.json
|
|
|
|
ln -s ${robertaMerges} roberta-base-merges.txt
|
2020-11-03 02:18:15 +00:00
|
|
|
ln -s ${albertVocab} albert-base-v1-tokenizer.json
|
2020-07-18 16:06:22 +00:00
|
|
|
ln -s ${bertVocab} bert-base-uncased-vocab.txt
|
2020-11-12 09:05:59 +00:00
|
|
|
ln -s ${docPipelineTokenizer} bert-wiki.json
|
|
|
|
ln -s ${docQuicktourTokenizer} tokenizer-wiki.json
|
2020-11-03 02:18:15 +00:00
|
|
|
ln -s ${norvigBig} big.txt
|
2020-07-18 16:06:22 +00:00
|
|
|
ln -s ${openaiVocab} openai-gpt-vocab.json
|
|
|
|
ln -s ${openaiMerges} openai-gpt-merges.txt )
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
preCheck = ''
|
2022-06-16 17:23:12 +00:00
|
|
|
export HOME=$(mktemp -d);
|
2021-02-05 17:12:51 +00:00
|
|
|
'';
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
pythonImportsCheck = [
|
|
|
|
"tokenizers"
|
|
|
|
];
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
disabledTests = [
|
2022-06-16 17:23:12 +00:00
|
|
|
# Downloads data using the datasets module
|
2021-02-05 17:12:51 +00:00
|
|
|
"TestTrainFromIterators"
|
2022-06-16 17:23:12 +00:00
|
|
|
# Those tests require more data
|
|
|
|
"test_from_pretrained"
|
|
|
|
"test_from_pretrained_revision"
|
|
|
|
"test_continuing_prefix_trainer_mistmatch"
|
2021-02-05 17:12:51 +00:00
|
|
|
];
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-07-18 16:06:22 +00:00
|
|
|
description = "Fast State-of-the-Art Tokenizers optimized for Research and Production";
|
2022-06-16 17:23:12 +00:00
|
|
|
homepage = "https://github.com/huggingface/tokenizers";
|
2020-07-18 16:06:22 +00:00
|
|
|
license = licenses.asl20;
|
2021-09-18 10:52:07 +00:00
|
|
|
maintainers = with maintainers; [ ];
|
2022-06-16 17:23:12 +00:00
|
|
|
platforms = platforms.unix;
|
2020-07-18 16:06:22 +00:00
|
|
|
};
|
|
|
|
}
|