TypeError running prediction task -> unexpected keyword argument #53

Closed
opened 2025-11-02 00:02:34 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @biyanisuraj on GitHub (Aug 3, 2023).

While running prediction task I receive type error

export EXPERIMENT_NAME="llm"
export RUN_ID=$(python madewithml/predict.py get-best-run-id --experiment-name $EXPERIMENT_NAME --metric val_loss --mode ASC)
python madewithml/predict.py predict \
    --run-id $RUN_ID \
    --title "Transfer learning with transformers" \
    --description "Using transformers for transfer learning on text classification tasks."

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/surajb/private/Made-With-ML/madewithml/predict.py:133 in predict                          │
│                                                                                                  │
│   130 │                                                                                          │
│   131 │   # Predict                                                                              │
│   132 │   sample_df = pd.DataFrame([{"title": title, "description": description, "tag": "other   │
│ ❱ 133 │   results = predict_with_proba(df=sample_df, predictor=predictor, index_to_class=prepr   │
│   134 │   logger.info(json.dumps(results, cls=NumpyEncoder, indent=2))                           │
│   135 │   return results                                                                         │
│   136                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ best_checkpoint = TorchCheckpoint(local_path=/private/tmp/mlflow/852956352849222177/3dab467… │ │
│ │     description = 'Using transformers for transfer learning on text classification tasks.'   │ │
│ │       predictor = TorchPredictor(model=FinetunedLLM(                                         │ │
│ │                     (llm): BertModel(                                                        │ │
│ │                   │   (embeddings): BertEmbeddings(                                          │ │
│ │                   │     (word_embeddings): Embedding(31090, 768, padding_idx=0)              │ │
│ │                   │     (position_embeddings): Embedding(512, 768)                           │ │
│ │                   │     (token_type_embeddings): Embedding(2, 768)                           │ │
│ │                   │     (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True)   │ │
│ │                   │     (dropout): Dropout(p=0.1, inplace=False)                             │ │
│ │                   │   )                                                                      │ │
│ │                   │   (encoder): BertEncoder(                                                │ │
│ │                   │     (layer): ModuleList(                                                 │ │
│ │                   │   │   (0-11): 12 x BertLayer(                                            │ │
│ │                   │   │     (attention): BertAttention(                                      │ │
│ │                   │   │   │   (self): BertSelfAttention(                                     │ │
│ │                   │   │   │     (query): Linear(in_features=768, out_features=768,           │ │
│ │                   bias=True)                                                                 │ │
│ │                   │   │   │     (key): Linear(in_features=768, out_features=768, bias=True)  │ │
│ │                   │   │   │     (value): Linear(in_features=768, out_features=768,           │ │
│ │                   bias=True)                                                                 │ │
│ │                   │   │   │     (dropout): Dropout(p=0.1, inplace=False)                     │ │
│ │                   │   │   │   )                                                              │ │
│ │                   │   │   │   (output): BertSelfOutput(                                      │ │
│ │                   │   │   │     (dense): Linear(in_features=768, out_features=768,           │ │
│ │                   bias=True)                                                                 │ │
│ │                   │   │   │     (LayerNorm): LayerNorm((768,), eps=1e-12,                    │ │
│ │                   elementwise_affine=True)                                                   │ │
│ │                   │   │   │     (dropout): Dropout(p=0.1, inplace=False)                     │ │
│ │                   │   │   │   )                                                              │ │
│ │                   │   │     )                                                                │ │
│ │                   │   │     (intermediate): BertIntermediate(                                │ │
│ │                   │   │   │   (dense): Linear(in_features=768, out_features=3072, bias=True) │ │
│ │                   │   │   │   (intermediate_act_fn): GELUActivation()                        │ │
│ │                   │   │     )                                                                │ │
│ │                   │   │     (output): BertOutput(                                            │ │
│ │                   │   │   │   (dense): Linear(in_features=3072, out_features=768, bias=True) │ │
│ │                   │   │   │   (LayerNorm): LayerNorm((768,), eps=1e-12,                      │ │
│ │                   elementwise_affine=True)                                                   │ │
│ │                   │   │   │   (dropout): Dropout(p=0.1, inplace=False)                       │ │
│ │                   │   │     )                                                                │ │
│ │                   │   │   )                                                                  │ │
│ │                   │     )                                                                    │ │
│ │                   │   )                                                                      │ │
│ │                   │   (pooler): BertPooler(                                                  │ │
│ │                   │     (dense): Linear(in_features=768, out_features=768, bias=True)        │ │
│ │                   │     (activation): Tanh()                                                 │ │
│ │                   │   )                                                                      │ │
│ │                     )                                                                        │ │
│ │                     (dropout): Dropout(p=0.5, inplace=False)                                 │ │
│ │                     (fc1): Linear(in_features=768, out_features=6, bias=True)                │ │
│ │                   ), preprocessor=<madewithml.data.CustomPreprocessor object at              │ │
│ │                   0x17fbc5b10>, use_gpu=False)                                               │ │
│ │    preprocessor = <madewithml.data.CustomPreprocessor object at 0x17fbc5b10>                 │ │
│ │          run_id = '3dab46713f524aa0a9a3df3227e0ca1f'                                         │ │
│ │       sample_df = │   │   │   │   │   │   │   │    title                                     │ │
│ │                   description    tag                                                         │ │
│ │                   0  Transfer learning with transformers  Using transformers for transfer    │ │
│ │                   learning on te...  other                                                   │ │
│ │           title = 'Transfer learning with transformers'                                      │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: predict_with_proba() got an unexpected keyword argument 'index_to_class'

I was able to successfully run predict task by removing the last argument 68e031d632/madewithml/predict.py (L133)

to match the function definition
68e031d632/madewithml/predict.py (L50-L53)

Originally created by @biyanisuraj on GitHub (Aug 3, 2023). While running prediction task I receive type error ``` export EXPERIMENT_NAME="llm" export RUN_ID=$(python madewithml/predict.py get-best-run-id --experiment-name $EXPERIMENT_NAME --metric val_loss --mode ASC) python madewithml/predict.py predict \ --run-id $RUN_ID \ --title "Transfer learning with transformers" \ --description "Using transformers for transfer learning on text classification tasks." ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /Users/surajb/private/Made-With-ML/madewithml/predict.py:133 in predict │ │ │ │ 130 │ │ │ 131 │ # Predict │ │ 132 │ sample_df = pd.DataFrame([{"title": title, "description": description, "tag": "other │ │ ❱ 133 │ results = predict_with_proba(df=sample_df, predictor=predictor, index_to_class=prepr │ │ 134 │ logger.info(json.dumps(results, cls=NumpyEncoder, indent=2)) │ │ 135 │ return results │ │ 136 │ │ │ │ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │ │ │ best_checkpoint = TorchCheckpoint(local_path=/private/tmp/mlflow/852956352849222177/3dab467… │ │ │ │ description = 'Using transformers for transfer learning on text classification tasks.' │ │ │ │ predictor = TorchPredictor(model=FinetunedLLM( │ │ │ │ (llm): BertModel( │ │ │ │ │ (embeddings): BertEmbeddings( │ │ │ │ │ (word_embeddings): Embedding(31090, 768, padding_idx=0) │ │ │ │ │ (position_embeddings): Embedding(512, 768) │ │ │ │ │ (token_type_embeddings): Embedding(2, 768) │ │ │ │ │ (LayerNorm): LayerNorm((768,), eps=1e-12, elementwise_affine=True) │ │ │ │ │ (dropout): Dropout(p=0.1, inplace=False) │ │ │ │ │ ) │ │ │ │ │ (encoder): BertEncoder( │ │ │ │ │ (layer): ModuleList( │ │ │ │ │ │ (0-11): 12 x BertLayer( │ │ │ │ │ │ (attention): BertAttention( │ │ │ │ │ │ │ (self): BertSelfAttention( │ │ │ │ │ │ │ (query): Linear(in_features=768, out_features=768, │ │ │ │ bias=True) │ │ │ │ │ │ │ (key): Linear(in_features=768, out_features=768, bias=True) │ │ │ │ │ │ │ (value): Linear(in_features=768, out_features=768, │ │ │ │ bias=True) │ │ │ │ │ │ │ (dropout): Dropout(p=0.1, inplace=False) │ │ │ │ │ │ │ ) │ │ │ │ │ │ │ (output): BertSelfOutput( │ │ │ │ │ │ │ (dense): Linear(in_features=768, out_features=768, │ │ │ │ bias=True) │ │ │ │ │ │ │ (LayerNorm): LayerNorm((768,), eps=1e-12, │ │ │ │ elementwise_affine=True) │ │ │ │ │ │ │ (dropout): Dropout(p=0.1, inplace=False) │ │ │ │ │ │ │ ) │ │ │ │ │ │ ) │ │ │ │ │ │ (intermediate): BertIntermediate( │ │ │ │ │ │ │ (dense): Linear(in_features=768, out_features=3072, bias=True) │ │ │ │ │ │ │ (intermediate_act_fn): GELUActivation() │ │ │ │ │ │ ) │ │ │ │ │ │ (output): BertOutput( │ │ │ │ │ │ │ (dense): Linear(in_features=3072, out_features=768, bias=True) │ │ │ │ │ │ │ (LayerNorm): LayerNorm((768,), eps=1e-12, │ │ │ │ elementwise_affine=True) │ │ │ │ │ │ │ (dropout): Dropout(p=0.1, inplace=False) │ │ │ │ │ │ ) │ │ │ │ │ │ ) │ │ │ │ │ ) │ │ │ │ │ ) │ │ │ │ │ (pooler): BertPooler( │ │ │ │ │ (dense): Linear(in_features=768, out_features=768, bias=True) │ │ │ │ │ (activation): Tanh() │ │ │ │ │ ) │ │ │ │ ) │ │ │ │ (dropout): Dropout(p=0.5, inplace=False) │ │ │ │ (fc1): Linear(in_features=768, out_features=6, bias=True) │ │ │ │ ), preprocessor=<madewithml.data.CustomPreprocessor object at │ │ │ │ 0x17fbc5b10>, use_gpu=False) │ │ │ │ preprocessor = <madewithml.data.CustomPreprocessor object at 0x17fbc5b10> │ │ │ │ run_id = '3dab46713f524aa0a9a3df3227e0ca1f' │ │ │ │ sample_df = │ │ │ │ │ │ │ │ title │ │ │ │ description tag │ │ │ │ 0 Transfer learning with transformers Using transformers for transfer │ │ │ │ learning on te... other │ │ │ │ title = 'Transfer learning with transformers' │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ TypeError: predict_with_proba() got an unexpected keyword argument 'index_to_class' ``` I was able to successfully run predict task by removing the last argument https://github.com/GokuMohandas/Made-With-ML/blob/68e031d63244b19283251e0476f77e8581dfddfb/madewithml/predict.py#L133 to match the function definition https://github.com/GokuMohandas/Made-With-ML/blob/68e031d63244b19283251e0476f77e8581dfddfb/madewithml/predict.py#L50-L53
Author
Owner

@GokuMohandas commented on GitHub (Aug 4, 2023):

Hi @biyanisuraj , great catch! I've updated the code to fix this mistake. Thanks for submitting this issue.

@GokuMohandas commented on GitHub (Aug 4, 2023): Hi @biyanisuraj , great catch! I've updated the code to fix this mistake. Thanks for submitting this issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/Made-With-ML#53