Skip to content

HuggingFaceSentimentAnalysis: generated code has an unused TensorFlow import #6794

Description

@kz930

What happened?

HuggingFaceSentimentAnalysisOpDesc.generatePythonCode emits an import for TFAutoModelForSequenceClassification that is never used:

common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDesc.scala

from transformers import pipeline
from transformers import AutoModelForSequenceClassification
from transformers import TFAutoModelForSequenceClassification   # <-- never used
from transformers import AutoTokenizer, AutoConfig

The generated body loads the model with the PyTorch AutoModelForSequenceClassification (self.model = AutoModelForSequenceClassification.from_pretrained(...)) and uses pipeline; TFAutoModelForSequenceClassification is not referenced anywhere in the generated code.

The TF* classes belong to transformers' TensorFlow backend, so importing this symbol forces a TensorFlow dependency. In a PyTorch-only environment (which is what the operator actually uses), from transformers import TFAutoModelForSequenceClassification raises an ImportError/RuntimeError at module load, crashing the whole generated script before any inference runs.

Expected: the generated code does not import unused TensorFlow-only symbols.

How to reproduce?

A — user-facing: Run a Hugging Face Sentiment Analysis operator in an environment where transformers is installed with the PyTorch backend but without TensorFlow. The generated script fails at import on the TFAutoModelForSequenceClassification line.

B — reproduced in a PyTorch-only env (transformers + torch, no tensorflow):

>>> from transformers import TFAutoModelForSequenceClassification
ImportError: cannot import name 'TFAutoModelForSequenceClassification' from 'transformers'

The other four imports the operator emits (pipeline, AutoModelForSequenceClassification, AutoTokenizer, AutoConfig) all import successfully in the same env — so removing just the unused TF... line fixes the crash. In main's generatePythonCode, TFAutoModelForSequenceClassification appears only on the import line (line 64) and is never referenced in the body (the model is loaded via AutoModelForSequenceClassification, line 75).

Proposed fix: remove the unused import:

 from transformers import pipeline
 from transformers import AutoModelForSequenceClassification
-from transformers import TFAutoModelForSequenceClassification
 from transformers import AutoTokenizer, AutoConfig

Version/Branch

1.3.0-incubating-SNAPSHOT (main)

Commit Hash (Optional)

No response

What browsers are you seeing the problem on?

No response

Relevant log output

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions