[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"tool-allenai--bilm-tf":3,"similar-allenai--bilm-tf":84},{"id":4,"github_repo":5,"name":6,"description_en":7,"description_zh":8,"ai_summary_zh":9,"readme_en":10,"readme_zh":11,"quickstart_zh":12,"use_case_zh":13,"hero_image_url":14,"owner_login":15,"owner_name":16,"owner_avatar_url":17,"owner_bio":18,"owner_company":19,"owner_location":19,"owner_email":20,"owner_twitter":19,"owner_website":21,"owner_url":22,"languages":23,"stars":36,"forks":37,"last_commit_at":38,"license":39,"difficulty_score":40,"env_os":41,"env_gpu":42,"env_ram":43,"env_deps":44,"category_tags":50,"github_topics":19,"view_count":53,"oss_zip_url":19,"oss_zip_packed_at":19,"status":54,"created_at":55,"updated_at":56,"faqs":57,"releases":83},4432,"allenai\u002Fbilm-tf","bilm-tf","Tensorflow implementation of contextualized word representations from bi-directional language models","bilm-tf 是基于 TensorFlow 实现的开源项目，专门用于构建和运行双向语言模型（biLM），以生成著名的 ELMo 上下文词向量。它源自论文《Deep contextualized word representations》，旨在解决传统词嵌入技术无法根据语境动态调整词义的痛点，让同一个词在不同句子中能拥有不同的向量表示，从而显著提升自然语言处理任务的理解能力。\n\n这款工具主要面向 AI 研究人员和深度学习开发者，特别是那些需要在 TensorFlow 1.x 环境下复现经典模型、训练自定义语言模型或将 ELMo 特征集成到下游任务中的技术团队。bilm-tf 的独特之处在于其灵活的集成策略：既支持直接从原始文本实时计算向量，也允许预计算并缓存中间结果以平衡效率与显存占用，适应从大规模数据集到小型实验的各种场景。此外，它提供了完整的训练与预测流程，并兼容 Docker 部署，方便用户在 GPU 环境中快速启动。虽然目前已有更便捷的 TensorFlow Hub 版本或 PyTorch 实现供简单调用，但 bilm-tf 依然是深入理解 ELMo 底层机制及进行定制化研究的","bilm-tf 是基于 TensorFlow 实现的开源项目，专门用于构建和运行双向语言模型（biLM），以生成著名的 ELMo 上下文词向量。它源自论文《Deep contextualized word representations》，旨在解决传统词嵌入技术无法根据语境动态调整词义的痛点，让同一个词在不同句子中能拥有不同的向量表示，从而显著提升自然语言处理任务的理解能力。\n\n这款工具主要面向 AI 研究人员和深度学习开发者，特别是那些需要在 TensorFlow 1.x 环境下复现经典模型、训练自定义语言模型或将 ELMo 特征集成到下游任务中的技术团队。bilm-tf 的独特之处在于其灵活的集成策略：既支持直接从原始文本实时计算向量，也允许预计算并缓存中间结果以平衡效率与显存占用，适应从大规模数据集到小型实验的各种场景。此外，它提供了完整的训练与预测流程，并兼容 Docker 部署，方便用户在 GPU 环境中快速启动。虽然目前已有更便捷的 TensorFlow Hub 版本或 PyTorch 实现供简单调用，但 bilm-tf 依然是深入理解 ELMo 底层机制及进行定制化研究的宝贵资源。","# bilm-tf\nTensorflow implementation of the pretrained biLM used to compute ELMo\nrepresentations from [\"Deep contextualized word representations\"](http:\u002F\u002Farxiv.org\u002Fabs\u002F1802.05365).\n\nThis repository supports both training biLMs and using pre-trained models for prediction.\n\nWe also have a pytorch implementation available in [AllenNLP](http:\u002F\u002Fallennlp.org\u002F).\n\nYou may also find it easier to use the version provided in [Tensorflow Hub](https:\u002F\u002Fwww.tensorflow.org\u002Fhub\u002Fmodules\u002Fgoogle\u002Felmo\u002F2) if you just like to make predictions.\n\nCitation:\n\n```\n@inproceedings{Peters:2018,\n  author={Peters, Matthew E. and  Neumann, Mark and Iyyer, Mohit and Gardner, Matt and Clark, Christopher and Lee, Kenton and Zettlemoyer, Luke},\n  title={Deep contextualized word representations},\n  booktitle={Proc. of NAACL},\n  year={2018}\n}\n```\n\n\n## Installing\nInstall python version 3.5 or later, tensorflow version 1.2 and h5py:\n\n```\npip install tensorflow-gpu==1.2 h5py\npython setup.py install\n```\n\nEnsure the tests pass in your environment by running:\n```\npython -m unittest discover tests\u002F\n```\n\n## Installing with Docker\n\nTo run the image, you must use nvidia-docker, because this repository\nrequires GPUs.\n```\nsudo nvidia-docker run -t allennlp\u002Fbilm-tf:training-gpu\n```\n\n## Using pre-trained models\n\nWe have several different English language pre-trained biLMs available for use.\nEach model is specified with two separate files, a JSON formatted \"options\"\nfile with hyperparameters and a hdf5 formatted file with the model\nweights.  Links to the pre-trained models are available [here](https:\u002F\u002Fallennlp.org\u002Felmo).\n\n\nThere are three ways to integrate ELMo representations into a downstream task, depending on your use case.\n\n1. Compute representations on the fly from raw text using character input.  This is the most general method and will handle any input text.  It is also the most computationally expensive.\n2. Precompute and cache the context independent token representations, then compute context dependent representations using the biLSTMs for input data.  This method is less computationally expensive then #1, but is only applicable with a fixed, prescribed vocabulary.\n3.  Precompute the representations for your entire dataset and save to a file.\n\nWe have used all of these methods in the past for various use cases.  #1 is necessary for evaluating at test time on unseen data (e.g. public SQuAD leaderboard). #2 is a good compromise for large datasets where the size of the file in #3 is unfeasible (SNLI, SQuAD).  #3 is a good choice for smaller datasets or in cases where you'd like to use ELMo in other frameworks.\n\nIn all cases, the process roughly follows the same steps.\nFirst, create a `Batcher` (or `TokenBatcher` for #2) to translate tokenized strings to numpy arrays of character (or token) ids.\nThen, load the pretrained ELMo model (class `BidirectionalLanguageModel`).\nFinally, for steps #1 and #2 use `weight_layers` to compute the final ELMo representations.\nFor #3, use `BidirectionalLanguageModel` to write all the intermediate layers to a file.\n\n#### Shape conventions\nEach tokenized sentence is a list of `str`, with a batch of sentences\na list of tokenized sentences (`List[List[str]]`).\n\nThe `Batcher` packs these into a shape\n`(n_sentences, max_sentence_length + 2, 50)` numpy array of character\nids, padding on the right with 0 ids for sentences less then the maximum\nlength.  The first and last tokens for each sentence are special\nbegin and end of sentence ids added by the `Batcher`.\n\nThe input character id placeholder can be dimensioned `(None, None, 50)`,\nwith both the batch dimension (axis=0) and time dimension (axis=1) determined\nfor each batch, up the the maximum batch size specified in the\n`BidirectionalLanguageModel` constructor.\n\nAfter running inference with the batch, the return biLM embeddings are\na numpy array with shape `(n_sentences, 3, max_sentence_length, 1024)`,\nafter removing the special begin\u002Fend tokens.\n\n#### Vocabulary file\nThe `Batcher` takes a vocabulary file as input for efficency.  This is a\ntext file, with one token per line, separated by newlines (`\\n`).\nEach token in the vocabulary is cached as the appropriate 50 character id\nsequence once.  Since the model is completely character based, tokens not in\nthe vocabulary file are handled appropriately at run time, with a slight\ndecrease in run time.  It is recommended to always include the special\n`\u003CS>` and `\u003C\u002FS>` tokens (case sensitive) in the vocabulary file.\n\n### ELMo with character input\n\nSee `usage_character.py` for a detailed usage example.\n\n### ELMo with pre-computed and cached context independent token representations\nTo speed up model inference with a fixed, specified vocabulary, it is\npossible to pre-compute the context independent token representations,\nwrite them to a file, and re-use them for inference.  Note that we don't\nsupport falling back to character inputs for out-of-vocabulary words,\nso this should only be used when the biLM is used to compute embeddings\nfor input with a fixed, defined vocabulary.\n\nTo use this option:\n\n1.  First create a vocabulary file with all of the unique tokens in your\ndataset and add the special `\u003CS>` and `\u003C\u002FS>` tokens.\n2.  Run `dump_token_embeddings` with the full model to write the token\nembeddings to a hdf5 file.\n3.  Use `TokenBatcher` (instead of `Batcher`) with your vocabulary file,\nand pass `use_token_inputs=False` and the name of the output file from step\n2 to the `BidirectonalLanguageModel` constructor.\n\nSee `usage_token.py` for a detailed usage example.\n\n### Dumping biLM embeddings for an entire dataset to a single file.\n\nTo take this option, create a text file with your tokenized dataset.  Each line is one tokenized sentence (whitespace separated).  Then use `dump_bilm_embeddings`.\n\nThe output file is `hdf5` format.  Each sentence in the input data is stored as a dataset with key `str(sentence_id)` where `sentence_id` is the line number in the dataset file (indexed from 0).\nThe embeddings for each sentence are a shape (3, n_tokens, 1024) array.\n\nSee `usage_cached.py` for a detailed example.\n\n## Training a biLM on a new corpus\n\nBroadly speaking, the process to train and use a new biLM is:\n\n1.  Prepare input data and a vocabulary file.\n2.  Train the biLM.\n3.  Test (compute the perplexity of) the biLM on heldout data.\n4.  Write out the weights from the trained biLM to a hdf5 file.\n5.  See the instructions above for using the output from Step #4 in downstream models.\n\n\n#### 1.  Prepare input data and a vocabulary file.\nTo train and evaluate a biLM, you need to provide:\n\n* a vocabulary file\n* a set of training files\n* a set of heldout files\n\nThe vocabulary file is a a text file with one token per line.  It must also include the special tokens `\u003CS>`, `\u003C\u002FS>` and `\u003CUNK>` (case sensitive) in the file.\n\n\u003Ci>IMPORTANT\u003C\u002Fi>: the vocabulary file should be sorted in descending order by token count in your training data.  The first three lines should be the special tokens (`\u003CS>`, `\u003C\u002FS>` and `\u003CUNK>`), then the most common token in the training data, ending with the least common token.\n\n\u003Ci>NOTE\u003C\u002Fi>: the vocabulary file used in training may differ from the one use for prediction.\n\nThe training data should be randomly split into many training files,\neach containing one slice of the data.  Each file contains pre-tokenized and\nwhite space separated text, one sentence per line.\nDon't include the `\u003CS>` or `\u003C\u002FS>` tokens in your training data.\n\nAll tokenization\u002Fnormalization is done before training a model, so both\nthe vocabulary file and training files should include normalized tokens.\nAs the default settings use a fully character based token representation, in general we do not recommend any normalization other then tokenization.\n\nFinally, reserve a small amount of the training data as heldout data for evaluating the trained biLM.\n\n#### 2.  Train the biLM.\nThe hyperparameters used to train the ELMo model can be found in `bin\u002Ftrain_elmo.py`.\n\nThe ELMo model was trained on 3 GPUs.\nTo train a new model with the same hyperparameters, first download the training data from the [1 Billion Word Benchmark](http:\u002F\u002Fwww.statmt.org\u002Flm-benchmark\u002F).\nThen download the [vocabulary file](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002Fvocab-2016-09-10.txt).\nFinally, run:\n\n```\nexport CUDA_VISIBLE_DEVICES=0,1,2\npython bin\u002Ftrain_elmo.py \\\n    --train_prefix='\u002Fpath\u002Fto\u002F1-billion-word-language-modeling-benchmark-r13output\u002Ftraining-monolingual.tokenized.shuffled\u002F*' \\\n    --vocab_file \u002Fpath\u002Fto\u002Fvocab-2016-09-10.txt \\\n    --save_dir \u002Foutput_path\u002Fto\u002Fcheckpoint\n```\n\n#### 3. Evaluate the trained model.\n\nUse `bin\u002Frun_test.py` to evaluate a trained model, e.g.\n\n```\nexport CUDA_VISIBLE_DEVICES=0\npython bin\u002Frun_test.py \\\n    --test_prefix='\u002Fpath\u002Fto\u002F1-billion-word-language-modeling-benchmark-r13output\u002Fheldout-monolingual.tokenized.shuffled\u002Fnews.en.heldout-000*' \\\n    --vocab_file \u002Fpath\u002Fto\u002Fvocab-2016-09-10.txt \\\n    --save_dir \u002Foutput_path\u002Fto\u002Fcheckpoint\n```\n\n#### 4. Convert the tensorflow checkpoint to hdf5 for prediction with `bilm` or `allennlp`.\n\nFirst, create an `options.json` file for the newly trained model.  To do so,\nfollow the template in an existing file (e.g. the [original `options.json`](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway\u002Felmo_2x4096_512_2048cnn_2xhighway_options.json) and modify for your hyperpararameters.\n\n**Important**: always set `n_characters` to 262 after training (see below).\n\nThen Run:\n\n```\npython bin\u002Fdump_weights.py \\\n    --save_dir \u002Foutput_path\u002Fto\u002Fcheckpoint\n    --outfile \u002Foutput_path\u002Fto\u002Fweights.hdf5\n```\n\n## Frequently asked questions and other warnings\n\n#### Can you provide the tensorflow checkpoint from training?\nThe tensorflow checkpoint is available by downloading these files:\n\n* [vocabulary](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002Fvocab-2016-09-10.txt)\n* [checkpoint](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fcheckpoint)\n* [options](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Foptions.json)\n* [1](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fmodel.ckpt-935588.data-00000-of-00001)\n* [2](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fmodel.ckpt-935588.index)\n* [3](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fmodel.ckpt-935588.meta)\n\n\n#### How to do fine tune a model on additional unlabeled data?\n\nFirst download the checkpoint files above.\nThen prepare the dataset as described in the section \"Training a biLM on a new corpus\", with the exception that we will use the existing vocabulary file instead of creating a new one.  Finally, use the script `bin\u002Frestart.py` to restart training with the existing checkpoint on the new dataset.\nFor small datasets (e.g. \u003C 10 million tokens) we only recommend tuning for a small number of epochs and monitoring the perplexity on a heldout set, otherwise the model will overfit the small dataset.\n\n#### Are the softmax weights available?\n\nThey are available in the training checkpoint above.\n\n#### Can you provide some more details about how the model was trained?\nThe script `bin\u002Ftrain_elmo.py` has hyperparameters for training the model.\nThe original model was trained on 3 GTX 1080 for 10 epochs, taking about\ntwo weeks.\n\nFor input processing, we used the raw 1 Billion Word Benchmark dataset\n[here](\nhttp:\u002F\u002Fwww.statmt.org\u002Flm-benchmark\u002F1-billion-word-language-modeling-benchmark-r13output.tar.gz), and the existing vocabulary of 793471 tokens, including `\u003CS>`, `\u003C\u002FS>` and `\u003CUNK>`.\nYou can find our vocabulary file [here](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002Fvocab-2016-09-10.txt).\nAt the model input, all text used the full character based representation,\nincluding tokens outside the vocab.\nFor the softmax output we replaced OOV tokens with `\u003CUNK>`.\n\nThe model was trained with a fixed size window of 20 tokens.\nThe batches were constructed by padding sentences with `\u003CS>` and `\u003C\u002FS>`, then packing tokens from one or more sentences into each row to fill completely fill each batch.\nPartial sentences and the LSTM states were carried over from batch to batch so that the language model could use information across batches for context, but backpropogation was broken at each batch boundary.\n\n#### Why do I get slightly different embeddings if I run the same text through the pre-trained model twice?\nAs a result of the training method (see above), the LSTMs are stateful, and carry their state forward from batch to batch.\nConsequently, this introduces a small amount of non-determinism, expecially\nfor the first two batches.\n\n#### Why does training seem to take forever even with my small dataset?\nThe number of gradient updates during training is determined by:\n\n* the number of tokens in the training data (`n_train_tokens`)\n* the batch size (`batch_size`)\n* the number of epochs (`n_epochs`)\n\nBe sure to set these values for your particular dataset in `bin\u002Ftrain_elmo.py`.\n\n\n#### What's the deal with `n_characters` and padding?\nDuring training, we fill each batch to exactly 20 tokens by adding `\u003CS>` and `\u003C\u002FS>` to each sentence, then packing tokens from one or more sentences into each row to fill completely fill each batch.\nAs a result, we do not allocate space for a special padding token.\nThe `UnicodeCharsVocabulary` that converts token strings to lists of character\nids always uses a fixed number of character embeddings of `n_characters=261`, so always\nset `n_characters=261` during training.\n\nHowever, for prediction, we ensure each sentence is fully contained in a single batch,\nand as a result pad sentences of different lengths with a special padding id.\nThis occurs in the `Batcher` [see here](https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fblob\u002Fmaster\u002Fbilm\u002Fdata.py#L220).\nAs a result, set `n_characters=262` during prediction in the `options.json`.\n\n#### How can I use ELMo to compute sentence representations?\nSimple methods like average and max pooling of the word level ELMo representations across sentences works well, often outperforming supervised methods on benchmark datasets.\nSee \"Evaluation of sentence embeddings in downstream and linguistic probing tasks\", Perone et al, 2018 [arxiv link](https:\u002F\u002Farxiv.org\u002Fabs\u002F1806.06259).\n\n\n#### I'm seeing a WARNING when serializing models, is it a problem?\nThe below warning can be safely ignored:\n```\n2018-08-24 13:04:08,779 : WARNING : Error encountered when serializing lstm_output_embeddings.\nType is unsupported, or the types of the items don't match field type in CollectionDef.\n'list' object has no attribute 'name'\n```\n","# bilm-tf\n用于从论文《深度上下文词表示》（[arXiv:1802.05365](http:\u002F\u002Farxiv.org\u002Fabs\u002F1802.05365)）中计算 ELMo 表示的预训练双向语言模型的 TensorFlow 实现。\n\n该仓库既支持训练双向语言模型，也支持使用预训练模型进行预测。\n\n我们还在 [AllenNLP](http:\u002F\u002Fallennlp.org\u002F) 中提供了 PyTorch 版本的实现。\n\n如果您只是想进行预测，使用 [TensorFlow Hub](https:\u002F\u002Fwww.tensorflow.org\u002Fhub\u002Fmodules\u002Fgoogle\u002Felmo\u002F2) 提供的版本可能会更加方便。\n\n引用：\n\n```\n@inproceedings{Peters:2018,\n  author={Peters, Matthew E. and  Neumann, Mark and Iyyer, Mohit and Gardner, Matt and Clark, Christopher and Lee, Kenton and Zettlemoyer, Luke},\n  title={Deep contextualized word representations},\n  booktitle={Proc. of NAACL},\n  year={2018}\n}\n```\n\n\n## 安装\n请安装 Python 3.5 或更高版本、TensorFlow 1.2 和 h5py：\n\n```\npip install tensorflow-gpu==1.2 h5py\npython setup.py install\n```\n\n确保在您的环境中运行测试通过：\n\n```\npython -m unittest discover tests\u002F\n```\n\n## 使用 Docker 安装\n\n要运行镜像，您必须使用 nvidia-docker，因为此仓库需要 GPU。\n```\nsudo nvidia-docker run -t allennlp\u002Fbilm-tf:training-gpu\n```\n\n## 使用预训练模型\n\n我们提供了多种不同的英语预训练双向语言模型供使用。每个模型由两个文件组成：一个 JSON 格式的超参数“选项”文件，以及一个 HDF5 格式的模型权重文件。预训练模型的下载链接可在 [这里](https:\u002F\u002Fallennlp.org\u002Felmo) 找到。\n\n根据您的应用场景，有三种方式可以将 ELMo 表示集成到下游任务中：\n\n1. 使用字符输入，从原始文本实时计算表示。这是最通用的方法，能够处理任何输入文本，但计算开销也最大。\n2. 预先计算并缓存与上下文无关的词元表示，然后使用双向 LSTM 对输入数据计算上下文相关的表示。这种方法比方法 1 计算开销小，但仅适用于固定且已知的词汇表。\n3. 预先计算整个数据集的表示，并将其保存到文件中。\n\n我们过去曾针对不同场景使用过这三种方法。方法 1 是在测试时评估未见过的数据（例如公开的 SQuAD 排行榜）所必需的；方法 2 是处理大型数据集时的一个折中方案，当方法 3 的文件过大而不可行时适用（如 SNLI、SQuAD）；方法 3 则适合较小的数据集，或者当您希望在其他框架中使用 ELMo 时。\n\n无论采用哪种方法，流程大致相同。首先，创建一个 `Batcher`（或对于方法 2 使用 `TokenBatcher`），将分词后的字符串转换为字符（或词元）ID 的 NumPy 数组。然后，加载预训练的 ELMo 模型（`BidirectionalLanguageModel` 类）。最后，对于方法 1 和方法 2，使用 `weight_layers` 计算最终的 ELMo 表示；而对于方法 3，则使用 `BidirectionalLanguageModel` 将所有中间层写入文件。\n\n#### 形状约定\n每个分词后的句子是一个 `str` 列表，一批句子则是分词后句子的列表（`List[List[str]]`）。\n\n`Batcher` 会将这些打包成形状为 `(n_sentences, max_sentence_length + 2, 50)` 的字符 ID NumPy 数组，长度不足最大值的句子会在右侧用 0 填充。每句的第一个和最后一个 token 是由 `Batcher` 添加的特殊句首和句尾标记。\n\n输入字符 ID 占位符的维度可以设置为 `(None, None, 50)`，其中批次维度（轴 0）和时间维度（轴 1）会根据每次批处理动态确定，上限由 `BidirectionalLanguageModel` 构造函数中指定的最大批次大小决定。\n\n对批次运行推理后，返回的 biLM 嵌入是一个形状为 `(n_sentences, 3, max_sentence_length, 1024)` 的 NumPy 数组，移除了特殊的句首\u002F句尾标记。\n\n#### 词汇表文件\n为了提高效率，`Batcher` 需要一个词汇表文件作为输入。这是一个文本文件，每行一个 token，以换行符 (`\\n`) 分隔。词汇表中的每个 token 只会被缓存一次，对应的 50 维字符 ID 序列也会被存储。由于模型完全基于字符，不在词汇表中的 token 在运行时仍能被正确处理，只是会略微降低运行速度。建议始终在词汇表中包含区分大小写的特殊标记 `\u003CS>` 和 `\u003C\u002FS>`。\n\n### 使用字符输入的 ELMo\n\n详细用法示例请参见 `usage_character.py`。\n\n### 使用预先计算并缓存的与上下文无关的词元表示\n\n为了加快具有固定词汇表的模型推理速度，可以预先计算与上下文无关的词元表示，将其保存到文件中，并在推理时重复使用。请注意，我们不支持对未登录词汇回退到字符输入，因此此方法仅适用于双向语言模型用于计算具有固定且明确词汇表的输入嵌入的情况。\n\n使用此方法的步骤如下：\n\n1. 首先，创建一个包含数据集中所有唯一 token 的词汇表，并添加特殊的 `\u003CS>` 和 `\u003C\u002FS>` 标记。\n2. 使用完整模型运行 `dump_token_embeddings`，将词元嵌入写入 HDF5 文件。\n3. 使用 `TokenBatcher`（而非 `Batcher`）配合您的词汇表文件，在 `BidirectionalLanguageModel` 构造函数中设置 `use_token_inputs=False`，并传入步骤 2 中生成的输出文件名。\n\n详细用法示例请参见 `usage_token.py`。\n\n### 将整个数据集的 biLM 嵌入转储到单个文件中\n\n要采用此方法，请创建一个包含分词后数据集的文本文件，每行是一个分词后的句子（以空格分隔）。然后使用 `dump_bilm_embeddings`。\n\n输出文件为 HDF5 格式。输入数据中的每句话都会以数据集的形式存储，键为 `str(sentence_id)`，其中 `sentence_id` 是数据集文件中的行号（从 0 开始计数）。每句话的嵌入是一个形状为 (3, n_tokens, 1024) 的数组。\n\n详细示例请参见 `usage_cached.py`。\n\n## 在新语料上训练双向语言模型\n\n广义上讲，训练和使用一个新的双向语言模型的流程如下：\n\n1. 准备输入数据和词汇表文件。\n2. 训练双向语言模型。\n3. 在保留数据上测试（计算困惑度）该双向语言模型。\n4. 将训练好的双向语言模型的权重导出到一个 HDF5 文件中。\n5. 参阅上述说明，了解如何在下游模型中使用第 4 步的输出。\n\n\n#### 1. 准备输入数据和词汇表文件。\n要训练和评估一个双向语言模型，你需要提供：\n\n* 词汇表文件\n* 一组训练文件\n* 一组保留文件\n\n词汇表文件是一个文本文件，每行包含一个词元。该文件还必须包含特殊词元 `\u003CS>`、`\u003C\u002FS>` 和 `\u003CUNK>`（区分大小写）。\n\n\u003Ci>重要提示\u003C\u002Fi>：词汇表文件应按照训练数据中各词元的出现频率降序排列。前三行应分别为特殊词元（`\u003CS>`、`\u003C\u002FS>` 和 `\u003CUNK>`），然后是训练数据中最常见的词元，最后是出现频率最低的词元。\n\n\u003Ci>注意\u003C\u002Fi>：用于训练的词汇表文件可能与用于预测的词汇表文件不同。\n\n训练数据应随机分割成多个训练文件，每个文件包含数据的一个子集。每个文件包含预分词且以空格分隔的文本，每行一个句子。请勿在训练数据中包含 `\u003CS>` 或 `\u003C\u002FS>` 词元。\n\n所有的分词和归一化处理都应在模型训练之前完成，因此词汇表文件和训练文件都应包含归一化的词元。由于默认设置采用完全基于字符的词元表示方式，通常我们不建议进行除分词之外的其他归一化处理。\n\n最后，从训练数据中保留一小部分作为保留数据，用于评估训练好的双向语言模型。\n\n#### 2. 训练双向语言模型。\n用于训练 ELMo 模型的超参数可以在 `bin\u002Ftrain_elmo.py` 中找到。\n\nELMo 模型是在 3 个 GPU 上训练的。要使用相同的超参数训练一个新的模型，首先从 [10 亿词基准](http:\u002F\u002Fwww.statmt.org\u002Flm-benchmark\u002F) 下载训练数据。然后下载 [词汇表文件](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002Fvocab-2016-09-10.txt)。最后运行以下命令：\n\n```\nexport CUDA_VISIBLE_DEVICES=0,1,2\npython bin\u002Ftrain_elmo.py \\\n    --train_prefix='\u002Fpath\u002Fto\u002F1-billion-word-language-modeling-benchmark-r13output\u002Ftraining-monolingual.tokenized.shuffled\u002F*' \\\n    --vocab_file \u002Fpath\u002Fto\u002Fvocab-2016-09-10.txt \\\n    --save_dir \u002Foutput_path\u002Fto\u002Fcheckpoint\n```\n\n#### 3. 评估训练好的模型。\n使用 `bin\u002Frun_test.py` 来评估训练好的模型，例如：\n\n```\nexport CUDA_VISIBLE_DEVICES=0\npython bin\u002Frun_test.py \\\n    --test_prefix='\u002Fpath\u002Fto\u002F1-billion-word-language-modeling-benchmark-r13output\u002Fheldout-monolingual.tokenized.shuffled\u002Fnews.en.heldout-000*' \\\n    --vocab_file \u002Fpath\u002Fto\u002Fvocab-2016-09-10.txt \\\n    --save_dir \u002Foutput_path\u002Fto\u002Fcheckpoint\n```\n\n#### 4. 将 TensorFlow 检查点转换为 HDF5 格式，以便使用 `bilm` 或 `allennlp` 进行预测。\n首先，为新训练的模型创建一个 `options.json` 文件。为此，请参考现有文件中的模板（例如原始的 [`options.json`](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway\u002Felmo_2x4096_512_2048cnn_2xhighway_options.json)），并根据你的超参数进行修改。\n\n**重要提示**：训练完成后，务必始终将 `n_characters` 设置为 262（见下文）。\n\n然后运行以下命令：\n\n```\npython bin\u002Fdump_weights.py \\\n    --save_dir \u002Foutput_path\u002Fto\u002Fcheckpoint\n    --outfile \u002Foutput_path\u002Fto\u002Fweights.hdf5\n```\n\n## 常见问题及其他注意事项\n\n#### 能否提供训练时的 TensorFlow 检查点文件？\nTensorFlow 检查点可通过下载以下文件获得：\n\n* [词汇表](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002Fvocab-2016-09-10.txt)\n* [检查点文件](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fcheckpoint)\n* [选项文件](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Foptions.json)\n* [模型数据文件 1](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fmodel.ckpt-935588.data-00000-of-00001)\n* [模型数据文件 2](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fmodel.ckpt-935588.index)\n* [模型元数据文件](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002F2x4096_512_2048cnn_2xhighway_tf_checkpoint\u002Fmodel.ckpt-935588.meta)\n\n\n#### 如何在额外的无标签数据上对模型进行微调？\n\n首先下载上述检查点文件。然后按照“在新语料库上训练 biLM”一节中的说明准备数据集，不同之处在于我们将使用现有的词汇表文件，而不是创建新的词汇表。最后，使用脚本 `bin\u002Frestart.py` 在新数据集上从现有检查点继续训练。\n对于小型数据集（例如少于 1000 万词），我们建议仅进行少量轮次的微调，并监控保留集上的困惑度；否则模型可能会过拟合小数据集。\n\n#### softmax 权重是否可用？\n\n它们包含在上述训练检查点中。\n\n#### 能否提供更多关于模型训练方式的细节？\n脚本 `bin\u002Ftrain_elmo.py` 中包含了用于训练模型的超参数。\n原始模型是在 3 张 GTX 1080 显卡上训练了 10 个 epoch，耗时约两周。\n\n在输入处理方面，我们使用了原始的 10 亿词基准数据集\n[这里](\nhttp:\u002F\u002Fwww.statmt.org\u002Flm-benchmark\u002F1-billion-word-language-modeling-benchmark-r13output.tar.gz)，以及包含 `\u003CS>`、`\u003C\u002FS>` 和 `\u003CUNK>` 的 793,471 个词的现有词汇表。我们的词汇表文件可在 [这里](https:\u002F\u002Fs3-us-west-2.amazonaws.com\u002Fallennlp\u002Fmodels\u002Felmo\u002Fvocab-2016-09-10.txt) 找到。\n在模型输入阶段，所有文本都采用完整的字符级表示，包括不在词汇表中的词。对于 softmax 输出，我们将 OOV 词替换为 `\u003CUNK>`。\n\n模型以固定大小的 20 个词窗口进行训练。批次是通过在句子前后添加 `\u003CS>` 和 `\u003C\u002FS>` 来构建的，然后将来自一个或多个句子的词打包到每一行中，以完全填满每个批次。部分句子和 LSTM 状态会从一个批次传递到下一个批次，使语言模型能够跨批次利用信息来获取上下文，但反向传播会在每个批次边界处中断。\n\n#### 为什么对同一段文本两次运行预训练模型会得到略有不同的嵌入结果？\n由于训练方法的原因（见上文），LSTM 是有状态的，其状态会从一个批次传递到下一个批次。因此，这会引入少量的非确定性，尤其是在前两个批次中。\n\n#### 为什么即使使用我的小数据集，训练似乎也需要很长时间？\n训练过程中梯度更新的次数由以下因素决定：\n\n* 训练数据中的词数 (`n_train_tokens`)\n* 批次大小 (`batch_size`)\n* 训练轮次 (`n_epochs`)\n\n请务必在 `bin\u002Ftrain_elmo.py` 中根据您的具体数据集设置这些值。\n\n\n#### `n_characters` 和填充有什么关系？\n在训练过程中，我们通过在每个句子前后添加 `\u003CS>` 和 `\u003C\u002FS>`，并将来自一个或多个句子的词打包到每一行中，以确保每个批次恰好包含 20 个词。因此，我们没有为特殊的填充标记预留空间。将词字符串转换为字符 ID 列表的 `UnicodeCharsVocabulary` 总是使用固定数量的字符嵌入，即 `n_characters=261`，所以在训练时应始终设置 `n_characters=261`。\n\n然而，在预测时，我们会确保每个句子完全包含在一个批次中，因此会对不同长度的句子使用特殊的填充 ID 进行填充。这一过程发生在 `Batcher` 类中 [参见此处](https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fblob\u002Fmaster\u002Fbilm\u002Fdata.py#L220)。因此，在预测时，应在 `options.json` 中将 `n_characters` 设置为 262。\n\n#### 如何使用 ELMo 计算句子表示？\n简单的方法，如对句子中单词级别的 ELMo 表示取平均值或最大池化，效果很好，通常在基准数据集上优于监督方法。详情请参阅 Perone 等人于 2018 年发表的论文《下游任务和语言学探针任务中句子嵌入的评估》[arXiv 链接](https:\u002F\u002Farxiv.org\u002Fabs\u002F1806.06259)。\n\n\n#### 序列化模型时出现警告，这是问题吗？\n可以安全地忽略以下警告：\n```\n2018-08-24 13:04:08,779 : WARNING : 序列化 lstm_output_embeddings 时遇到错误。\n类型不受支持，或者项目类型与 CollectionDef 中的字段类型不匹配。\n'list' 对象没有 'name' 属性\n```","# bilm-tf 快速上手指南\n\nbilm-tf 是 ELMo（Deep contextualized word representations）预训练双向语言模型（biLM）的 TensorFlow 实现。本工具支持从头训练 biLM 模型，也支持加载预训练模型进行特征提取。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux (推荐，特别是使用 GPU 时) 或 macOS\n*   **Python 版本**: 3.5 或更高\n*   **TensorFlow 版本**: 1.2 (注意：此项目依赖较旧版本的 TF)\n*   **GPU 支持**: 如需加速推理或训练，需安装 `tensorflow-gpu` 并配置好 NVIDIA 驱动及 CUDA 环境。\n*   **其他依赖**: `h5py`\n\n> **提示**: 由于该项目依赖 TensorFlow 1.2，建议在使用前创建独立的虚拟环境（如 `venv` 或 `conda`），以免与现有项目冲突。\n\n## 安装步骤\n\n### 方法一：pip 直接安装\n\n1.  安装核心依赖包（建议使用国内镜像源加速下载）：\n    ```bash\n    pip install -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple tensorflow-gpu==1.2 h5py\n    ```\n    *注：若无 GPU 环境，可将 `tensorflow-gpu` 替换为 `tensorflow==1.2`。*\n\n2.  克隆源码并安装：\n    ```bash\n    git clone https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf.git\n    cd bilm-tf\n    python setup.py install\n    ```\n\n3.  （可选）验证安装是否成功：\n    ```bash\n    python -m unittest discover tests\u002F\n    ```\n\n### 方法二：使用 Docker (推荐用于训练)\n\n如果您希望避免复杂的环境配置，特别是需要 GPU 支持时，可以使用官方提供的 Docker 镜像：\n\n```bash\nsudo nvidia-docker run -t allennlp\u002Fbilm-tf:training-gpu\n```\n\n## 基本使用\n\n本工具主要提供三种使用预训练 ELMo 模型的方式。对于大多数开发者，**方式一（基于字符输入实时计算）**是最通用且最简单的入门方法。\n\n### 前置准备：下载预训练模型\n\n在使用前，您需要从 AllenNLP 官网下载预训练好的模型文件。每个模型包含两个文件：\n1.  **options 文件**: JSON 格式，包含超参数。\n2.  **weights 文件**: HDF5 格式，包含模型权重。\n\n下载地址：[https:\u002F\u002Fallennlp.org\u002Felmo](https:\u002F\u002Fallennlp.org\u002Felmo)\n*(国内用户若下载缓慢，可尝试寻找国内镜像或使用代理)*\n\n假设您已下载以下两个文件到当前目录：\n*   `elmo_2x4096_512_2048cnn_2xhighway_options.json`\n*   `elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5`\n\n### 使用示例：基于字符输入实时计算 (Character Input)\n\n这种方式不需要预先构建词表缓存，可以直接处理任意文本，但计算开销相对较大。\n\n参考项目中的 `usage_character.py`，核心代码如下：\n\n```python\nimport tensorflow as tf\nimport numpy as np\nfrom bilm import Batcher, BidirectionalLanguageModel, weight_layers\n\n# 1. 准备数据\n# 输入格式：列表的列表，外层是句子批次，内层是分词后的单词列表\nsentences = [\n    ['First', 'sentence', '.'],\n    ['Another', 'sentence', '.']\n]\n\n# 2. 创建 Batcher\n# vocab_file 用于提高效率，若没有特定词表文件，可创建一个包含 \u003CS>, \u003C\u002FS> 的基础文件\n# 这里假设你有一个 vocab.txt，每行一个词\nvocab_file = 'vocab.txt' \nbatcher = Batcher(vocab_file=vocab_file)\n\n# 将句子转换为字符 ID 的 numpy 数组\n# 形状：(n_sentences, max_sentence_length + 2, 50)\nchar_ids = batcher.batch_sentences(sentences)\n\n# 3. 加载预训练模型\noptions_file = 'elmo_2x4096_512_2048cnn_2xhighway_options.json'\nweights_file = 'elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5'\n\nbiLM = BidirectionalLanguageModel(options_file, weights_file)\n\n# 4. 构建计算图并运行\ntf.reset_default_graph()\n\n# 创建占位符\nchars_op = tf.placeholder(tf.int32, shape=(None, None, 50))\n\n# 运行 biLM 获取所有层的输出\nbiLM_out = biLM(chars_op)\n\n# 使用 weight_layers 计算最终的 ELMo 表示 (加权求和)\n# 这里演示获取顶层输出，实际使用中通常结合多层\nelmo_embeddings = weight_layers('elmo', biLM_out, use_top_only=False)\n\nwith tf.Session() as sess:\n    sess.run(tf.global_variables_initializer())\n    \n    # 执行推理\n    embeddings_val = sess.run(\n        elmo_embeddings['weighted_op'],\n        feed_dict={chars_op: char_ids}\n    )\n\n# 输出形状说明\n# embeddings_val 形状为: (n_sentences, 3, max_sentence_length, 1024)\n# 其中维度 3 代表：底层、中间层、顶层 的拼接或加权结果\nprint(\"Embeddings shape:\", embeddings_val.shape)\n```\n\n### 进阶选项简述\n\n如果您的应用场景对速度有极高要求且词汇表固定，可以考虑以下两种优化方案（详见源码中的 `usage_token.py` 和 `usage_cached.py`）：\n\n1.  **缓存上下文无关的词向量**: 预先计算并保存 token 级别的嵌入，推理时仅通过 biLSTM 计算上下文相关部分。适用于词汇表固定的大型数据集。\n2.  **离线 dump 整个数据集**: 将整个数据集的 ELMo 向量预先计算并保存为 HDF5 文件，下游任务直接读取。适用于小型数据集或跨框架使用。","某金融科技公司的 NLP 团队正在构建一个智能客服系统，需要精准识别用户投诉文本中多义词（如“透支”在金融与日常语境下的不同含义）的真实意图。\n\n### 没有 bilm-tf 时\n- 模型只能生成静态词向量，无法区分“苹果”是指水果还是科技公司，导致意图分类准确率卡在 75% 难以突破。\n- 面对新出现的金融黑话或拼写变体，由于缺乏字符级编码能力，模型直接将其视为未知词（OOV）并忽略关键信息。\n- 团队若想复现论文中的 ELMo 效果，需从零搭建双向语言模型架构，耗费数周时间调试 TensorFlow 底层代码。\n- 在处理长句投诉时，上下文依赖捕捉能力弱，经常误判用户的情绪倾向。\n\n### 使用 bilm-tf 后\n- 利用 bilm-tf 预训练的双向语言模型生成动态上下文词向量，同一词汇在不同句子中获得不同表示，意图识别准确率提升至 92%。\n- 通过其内置的字符级 Batcher 处理输入，即使遇到未登录的新造词或拼写错误，也能基于字符组合提取有效特征。\n- 直接加载官方提供的预训练权重文件，无需重新训练底层模型，仅需一天即可完成从数据接入到下游任务集成的全流程。\n- 借助深层双向 LSTM 结构，模型能精准捕捉长距离依赖关系，显著改善了对复杂投诉逻辑的理解能力。\n\nbilm-tf 让团队以最低成本将前沿的上下文感知能力落地，彻底解决了传统静态词向量在垂直领域语义理解上的瓶颈。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fallenai_bilm-tf_ac42f6b9.png","allenai","Ai2","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fallenai_65c450d5.png","",null,"ai2-info@allenai.org","http:\u002F\u002Fwww.allenai.org","https:\u002F\u002Fgithub.com\u002Fallenai",[24,28,32],{"name":25,"color":26,"percentage":27},"Python","#3572A5",99,{"name":29,"color":30,"percentage":31},"Dockerfile","#384d54",0.8,{"name":33,"color":34,"percentage":35},"Shell","#89e051",0.1,1613,447,"2025-11-17T09:07:23","Apache-2.0",3,"Linux","训练必需 NVIDIA GPU（原文提及使用 3 张 GTX 1080），需安装 nvidia-docker；预测未强制要求但建议使用。CUDA 版本需与 TensorFlow 1.2 兼容。","未说明",{"notes":45,"python":46,"dependencies":47},"该工具基于较旧的 TensorFlow 1.2 版本。若使用 Docker 运行必须使用 nvidia-docker。训练原始模型需在 3 张 GTX 1080 GPU 上运行约两周。词汇表文件必须按词频降序排列，且前三行必须是特殊令牌 \u003CS>、\u003C\u002FS> 和 \u003CUNK>。","3.5+",[48,49],"tensorflow-gpu==1.2","h5py",[51,52],"语言模型","开发框架",2,"ready","2026-03-27T02:49:30.150509","2026-04-06T22:01:56.094680",[58,63,68,73,78],{"id":59,"question_zh":60,"answer_zh":61,"source_url":62},20143,"预训练模型的下载链接失效或无法点击怎么办？","这是一个已知问题，标签中的链接地址丢失。临时解决方案是参考迁移前的 ELMo 网站 HTML 源代码获取资源：https:\u002F\u002Fgithub.com\u002Fallenai\u002Fallennlp-website\u002Fblob\u002Fmaster\u002Felmo.html。维护者表示会修复此问题。","https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fissues\u002F245",{"id":64,"question_zh":65,"answer_zh":66,"source_url":67},20144,"如何在训练时避免 CPU 内存溢出（OOM）错误？","当遇到类似 'Resource exhausted: OOM when allocating tensor' 的错误时，通常是因为词汇表过大。建议减小词汇表大小。原始训练数据（除最大模型外）的词汇表大小为 793,471，构建方法是丢弃所有出现次数低于 3 的单词。可以使用脚本重新生成较小的词汇表文件。","https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fissues\u002F174",{"id":69,"question_zh":70,"answer_zh":71,"source_url":72},20145,"运行单元测试时出现段错误（Segfault）或 CuDNN 版本不匹配错误如何解决？","这通常是由于安装的 CUDA\u002FCuDNN 版本与 TensorFlow 期望的版本不匹配导致的。例如错误提示 'Loaded runtime CuDNN library: 7.1.4 but source was compiled with: 7.2.1'。解决方法包括：1. 升级或降级 CuDNN 库以匹配 TensorFlow 版本；2. 尝试安装 tf-nightly 构建版本，这通常能解决兼容性问题。","https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fissues\u002F110",{"id":74,"question_zh":75,"answer_zh":76,"source_url":77},20146,"如何将微调后的模型导出为 SavedModel 格式以便在 TensorFlow Serving 中使用？","虽然用户需要导出为 SavedModel 格式，但在实际测试中，直接使用 Checkpoint 加载模型在 TensorFlow 2 中运行流畅。如果必须使用 Serving，需检查 model.py 中相关导出逻辑（参考代码行：https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fblob\u002F7cffee2b0986be51f5e2a747244836e1047657f4\u002Fbilm\u002Fmodel.py#L587-L593）。不过许多用户发现直接使用 Streamlit 等工具原生加载 Checkpoint 更为简便。","https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fissues\u002F238",{"id":79,"question_zh":80,"answer_zh":81,"source_url":82},20147,"如何贡献其他语言（如德语）的 ELMo 模型？","用户可以训练特定语言的 ELMo 模型并提交给维护者，以便链接到 'Contributed ELMo Models' 页面。贡献时需提供模型仓库链接（如 GitHub Repo），并说明许可证信息（如 BSD-2-Clause）。如果提供了用于微调的 checkpoint 文件会更受欢迎。维护者审核后会更新官方列表。","https:\u002F\u002Fgithub.com\u002Fallenai\u002Fbilm-tf\u002Fissues\u002F209",[],[85,96,104,112,120,128],{"id":86,"name":87,"github_repo":88,"description_zh":89,"stars":90,"difficulty_score":40,"last_commit_at":91,"category_tags":92,"status":54},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,"2026-04-06T06:32:30",[93,52,94,95],"Agent","图像","数据工具",{"id":97,"name":98,"github_repo":99,"description_zh":100,"stars":101,"difficulty_score":40,"last_commit_at":102,"category_tags":103,"status":54},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[52,94,93],{"id":105,"name":106,"github_repo":107,"description_zh":108,"stars":109,"difficulty_score":53,"last_commit_at":110,"category_tags":111,"status":54},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",141543,"2026-04-06T11:32:54",[52,93,51],{"id":113,"name":114,"github_repo":115,"description_zh":116,"stars":117,"difficulty_score":53,"last_commit_at":118,"category_tags":119,"status":54},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107888,"2026-04-06T11:32:50",[52,94,93],{"id":121,"name":122,"github_repo":123,"description_zh":124,"stars":125,"difficulty_score":40,"last_commit_at":126,"category_tags":127,"status":54},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[51,94,93,52],{"id":129,"name":130,"github_repo":131,"description_zh":132,"stars":133,"difficulty_score":40,"last_commit_at":134,"category_tags":135,"status":54},4292,"Deep-Live-Cam","hacksider\u002FDeep-Live-Cam","Deep-Live-Cam 是一款专注于实时换脸与视频生成的开源工具，用户仅需一张静态照片，即可通过“一键操作”实现摄像头画面的即时变脸或制作深度伪造视频。它有效解决了传统换脸技术流程繁琐、对硬件配置要求极高以及难以实时预览的痛点，让高质量的数字内容创作变得触手可及。\n\n这款工具不仅适合开发者和技术研究人员探索算法边界，更因其极简的操作逻辑（仅需三步：选脸、选摄像头、启动），广泛适用于普通用户、内容创作者、设计师及直播主播。无论是为了动画角色定制、服装展示模特替换，还是制作趣味短视频和直播互动，Deep-Live-Cam 都能提供流畅的支持。\n\n其核心技术亮点在于强大的实时处理能力，支持口型遮罩（Mouth Mask）以保留使用者原始的嘴部动作，确保表情自然精准；同时具备“人脸映射”功能，可同时对画面中的多个主体应用不同面孔。此外，项目内置了严格的内容安全过滤机制，自动拦截涉及裸露、暴力等不当素材，并倡导用户在获得授权及明确标注的前提下合规使用，体现了技术发展与伦理责任的平衡。",88924,"2026-04-06T03:28:53",[52,94,93,136],"视频"]