Skip to content

Commit 1fa19ea

Browse files
Bugfix: Allow passing model file name to pipeline and auto models
1 parent 715e2f7 commit 1fa19ea

3 files changed

Lines changed: 36 additions & 30 deletions

File tree

docs/pipelines.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ this allows you to modify the cache directory to save and look for models for th
7171
This specified model version to use. It can be a branch name, a tag name, or a commit id. Since HuggingFace uses a
7272
git-based system for storing models and other artifacts, so ``revision`` can be any identifier allowed by git.
7373

74+
### `modelFilename`
75+
76+
This specified the filename of the model in the repository. It's particularly used for decoder only models. It defaults
77+
to `decoder_model_merged` but you can set it to use another if the repository doesn't use that nomenclature.
78+
7479
## Running a Pipeline
7580

7681
Once you've created a pipeline, running it is straightforward. All pipelines are designed to accept input text as their
@@ -143,25 +148,24 @@ and for the translation task:
143148

144149
| Task | ID | Description | Supported? |
145150
|-----------------------------------------------------------------------------------|-----------------------------------------------|------------------------------------------------------------------------------------------------|------------|
146-
| [Fill-Mask](/fill-mask) | `fill-mask` | Masking some of the words in a sentence and predicting which words should replace those masks. ||
147-
| [Question Answering](/question-answering) | `question-answering` | Retrieve the answer to a question from a given text. ||
148-
| [Sentence Similarity](/feature-extraction) | `sentence-similarity` | Determining how similar two texts are. ||
149-
| [Summarization](/summarization) | `summarization` | Producing a shorter version of a document while preserving its important information. ||
151+
| [Fill-Mask](/fill-mask) | `fill-mask` | Masking some of the words in a sentence and predicting which words should replace those masks. ||
152+
| [Question Answering](/question-answering) | `question-answering` | Retrieve the answer to a question from a given text. ||
153+
| [Sentence Similarity](/feature-extraction) | `sentence-similarity` | Determining how similar two texts are. ||
154+
| [Summarization](/summarization) | `summarization` | Producing a shorter version of a document while preserving its important information. ||
150155
| [Table Question Answering](https://huggingface.co/tasks/table-question-answering) | `table-question-answering` | Answering a question about information from a given table. ||
151-
| [Text Classification](/text-classification) | `text-classification` or `sentiment-analysis` | Assigning a label or class to a given text. ||
152-
| [Text Generation](/text-generation) | `text-generation` | Producing new text by predicting the next word in a sequence. ||
153-
| [Text-to-text Generation](/text-to-text-generation) | `text2text-generation` | Converting one text sequence into another text sequence. ||
154-
| [Token Classification](/token-classification) | `token-classification` or `ner` | Assigning a label to each token in a text. ||
155-
| [Translation](/translation) | `translation` | Converting text from one language to another. ||
156-
| [Zero-Shot Classification](/zero-shot-classification) | `zero-shot-classification` | Classifying text into classes that are unseen during training. ||
156+
| [Text Classification](/text-classification) | `text-classification` or `sentiment-analysis` | Assigning a label or class to a given text. ||
157+
| [Text Generation](/text-generation) | `text-generation` | Producing new text by predicting the next word in a sequence. ||
158+
| [Text-to-text Generation](/text-to-text-generation) | `text2text-generation` | Converting one text sequence into another text sequence. ||
159+
| [Token Classification](/token-classification) | `token-classification` or `ner` | Assigning a label to each token in a text. ||
160+
| [Translation](/translation) | `translation` | Converting text from one language to another. ||
161+
| [Zero-Shot Classification](/zero-shot-classification) | `zero-shot-classification` | Classifying text into classes that are unseen during training. ||
157162

158163
## Supported Model Architectures
159164

160165
TransformersPHP supports a wide range of model architectures for various NLP tasks. If the specific model you're
161166
interested in isn't listed here, you can open an issue on the repository so we can add support for it. Here's a list of
162167
currently tested and supported model architectures:
163168

164-
165169
1. **[ALBERT](https://huggingface.co/docs/transformers/model_doc/albert)** (from Google Research and the Toyota
166170
Technological Institute at Chicago) released with the
167171
paper [ALBERT: A Lite BERT for Self-supervised Learning of Language Representations](https://arxiv.org/abs/1909.11942),

src/Pipelines/Pipeline.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ public function __invoke(array|string $texts, ...$args): array
5555
* @throws UnsupportedTaskException If the task is not supported.
5656
*/
5757
function pipeline(
58-
string|Task $task,
59-
?string $modelName = null,
60-
bool $quantized = true,
61-
?array $config = null,
62-
?string $cacheDir = null,
63-
string $revision = 'main',
58+
string|Task $task,
59+
?string $modelName = null,
60+
bool $quantized = true,
61+
?array $config = null,
62+
?string $cacheDir = null,
63+
string $revision = 'main',
64+
?string $modelFilename = null,
6465
?OutputInterface $output = null
6566
): Pipeline
6667
{
@@ -75,7 +76,7 @@ function pipeline(
7576

7677
$modelName ??= $task->defaultModelName();
7778

78-
$model = $task->pretrainedModel($modelName, $quantized, $config, $cacheDir, $revision, $output);
79+
$model = $task->pretrainedModel($modelName, $quantized, $config, $cacheDir, $revision, $modelFilename, $output);
7980

8081
$tokenizer = AutoTokenizer::fromPretrained($modelName, $quantized, $config, $cacheDir, $revision, $output);
8182

src/Pipelines/Task.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,35 @@ public function defaultModelName(): string
8686
}
8787

8888
public function pretrainedModel(
89-
string $modelNameOrPath,
90-
bool $quantized = true,
91-
?array $config = null,
92-
?string $cacheDir = null,
93-
string $revision = 'main',
89+
string $modelNameOrPath,
90+
bool $quantized = true,
91+
?array $config = null,
92+
?string $cacheDir = null,
93+
string $revision = 'main',
94+
?string $modelFilename = null,
9495
?OutputInterface $output = null
9596
): PreTrainedModel
9697
{
9798
return match ($this) {
9899
self::SentimentAnalysis,
99100
self::TextClassification,
100-
self::ZeroShotClassification => AutoModelForSequenceClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
101+
self::ZeroShotClassification => AutoModelForSequenceClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
101102

102-
self::FillMask => AutoModelForMaskedLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
103+
self::FillMask => AutoModelForMaskedLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
103104

104-
self::QuestionAnswering => AutoModelForQuestionAnswering::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
105+
self::QuestionAnswering => AutoModelForQuestionAnswering::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
105106

106107
self::FeatureExtraction,
107-
self::Embeddings => AutoModel::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
108+
self::Embeddings => AutoModel::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
108109

109110
self::Text2TextGeneration,
110111
self::Translation,
111-
self::Summarization => AutoModelForSeq2SeqLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
112+
self::Summarization => AutoModelForSeq2SeqLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
112113

113-
self::TextGeneration => AutoModelForCausalLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
114+
self::TextGeneration => AutoModelForCausalLM::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
114115

115116
self::TokenClassification,
116-
self::Ner => AutoModelForTokenClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $output),
117+
self::Ner => AutoModelForTokenClassification::fromPretrained($modelNameOrPath, $quantized, $config, $cacheDir, $revision, $modelFilename, $output),
117118
};
118119
}
119120
}

0 commit comments

Comments
 (0)