question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Call to pipeline.predict() fails

See original GitHub issue

System Info

  • transformers version: 4.21.1
  • Platform: macOS-12.5.1-arm64-arm-64bit
  • Python version: 3.9.12
  • Huggingface_hub version: 0.2.1
  • PyTorch version (GPU?): 1.12.1 (False)
  • Tensorflow version (GPU?): 2.9.2 (False)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?: No

Who can help?

@narsil

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, …)
  • My own task or dataset (give details below)

Reproduction

Execute the following piece of code resulted in an exception that is pasted below.

from transformers import pipeline

pipe = pipeline("text-classification")
print(pipe.predict(["This restaurant is awesome"]))

Exception:

Traceback (most recent call last):
  File "pipeline_test.py", line 5, in <module>
    print(pipe.predict(["This restaurant is awesome"]))
  File "miniconda3/envs/mlflow-py3.9/lib/python3.9/site-packages/transformers/pipelines/base.py", line 840, in predict
    return self(X=X)
  File "miniconda3/envs/mlflow-py3.9/lib/python3.9/site-packages/transformers/pipelines/text_classification.py", line 138, in __call__
    result = super().__call__(*args, **kwargs)
TypeError: __call__() missing 1 required positional argument: 'inputs'

Expected behavior

Successful predictions as shown below

[{'label': 'POSITIVE', 'score': 0.9998743534088135}]

Proposed fix

I dig a bit deeper into the implementation based on the exception and found out that this change fixes the issue. If this indeed a fix, I am happy to create a PR.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Narsilcommented, Oct 7, 2022

I will go ahead and create a PR. Prior to that I will run all the tests to make sure, the fix does not introduce any breaking changes. Let us see how it rolls 😃

Thanks ! Again as I said, this is very old code maybe it broke a long time ago already and your PR is good (and we probably need to add a test to make sure we don’t break again).

1reaction
s-udhayacommented, Oct 6, 2022

Hi @Narsil ,

If that is the core of the issue (which sounds odd) can’t you just wrap the pipeline in another dummy object that just uses predict to use __call__ ?

This is exactly what happens in Pipeline’s predict method. I would rather prefer to fix the issue at the source than creating a workaround.

The problem is that because the purpose of this code as since been lost, we would be very hesitant to change it because of our commitment to never make breaking changes.

I understand your concern regarding breaking changes. however I believe, this change is not going to be a breaking change, and the predict function is not usable in its current state.

I will go ahead and create a PR. Prior to that I will run all the tests to make sure, the fix does not introduce any breaking changes. Let us see how it rolls 😃

Thanks for the response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pipeline Sklearn ( missing basic ) Predictions Error
This dataset is KC Housing Dataset from Kaggle. I am trying to build a simple Linear regression , using Pipelines. However, I am...
Read more >
sklearn Pipeline
Call transform of each transformer in the pipeline. The transformed data are finally passed to the final estimator that calls predict method.
Read more >
Error getting prediction explanation using shap_values ...
I am building an NLP model to predict language type (C/C++/C#/Python...) for a given code. Now I need to provide an explanation for...
Read more >
Getting online predictions with scikit-learn - AI Platform
You can deploy and serve scikit-learn pipelines on AI Platform Prediction. ... your request to create an AI Platform Prediction model version fails....
Read more >
How to Improve Machine Learning Code Quality with Scikit ...
The Scikit-learn library has tools called Pipeline and ... Our goal is to predict whether a candidate will change jobs based on their ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found