# Bert-base for text classification and MLFlow

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbert-base-for-text-classification-and-mlflow%2F115601%3E%5C
**Category:** 🤗Transformers\
**Created:** [November 4, 2024, 9:11am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbert-base-for-text-classification-and-mlflow%2F115601 "2024-11-04T09:11:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petrina](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@Petrina](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FPetrina)%5C
**Post date:** [November 4, 2024, 9:11am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbert-base-for-text-classification-and-mlflow%2F115601%2F1 "2024-11-04T09:11:00Z")

</div>

Hello!

I am currently trying to fine-tune bert-base-uncased using a dataset for hate-speech detection, so I am loading the model using `AutoModelForSequenceClassification` function and the number of classes I have.

As I have seen in the documentation, the classifier with the suitable number of classification heads is loaded on top of Bert and the model can be fine-tuned for the downstream task of hate speech detection. Although the training is performed and completed without any errors, when I try to perform training with logging the experiment on MLflow the following error occurs:

> mlflow.exceptions.RestException: INVALID\_PARAMETER\_VALUE: Changing param values is not allowed. Params were already logged=‘[{‘key’: ‘problem\_type’, ‘old\_value’: ‘None’, ‘new\_value’: ‘single\_label\_classification’}]’ for run ID=‘e59139f9  
> 7fb24f0b8242728892323d37’.

which means that originally the parameter problem\_type is logged as None in MLflow and then it takes the value single\_label\_classification and cannot be logged due to different value.

Is this a bug? Is there any solution other than just hard-coding the parameter before logging it to MLflow?

Thank you in advance,  
Petrina

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [November 4, 2024, 1:29pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbert-base-for-text-classification-and-mlflow%2F115601%2F2 "2024-11-04T13:29:58Z")

</div>

It looks very similar to this bug, but either the remnants of the bug or the library version is out of date.

> <https://github.com/mlflow/mlflow/issues/7152>
>
> \### Issues Policy acknowledgement
> 
> \- \[X\] I have read and agree to submit bug r…eports in accordance with the \[issues policy\](https://www.github.com/mlflow/mlflow/blob/master/ISSUE\_POLICY.md)
> 
> \### Willingness to contribute
> 
> No. I cannot contribute a bug fix at this time.
> 
> \### MLflow version
> 
> 1.30.0
> 
> \### System information
> 
> \- \*\*OS Platform and Distribution (e.g., Linux Ubuntu 16.04)\*\*: WSL Ubuntu 20.04
> \- \*\*Python version\*\*: 3.10.6
> \- \*\*yarn version, if running the dev UI\*\*: N/A
> 
> 
> \### Describe the problem
> 
> Autologging for TensorFlow (tf.keras) works when I run just \`python train.py\` but not when I run it from \`mlflow run\` on the MLproject (which uses the same \`train.py\` script).
> 
> It appears that the autologger logs the state of the model during creation and this prevents it from updating the log values after training.
> 
> Here's the error I get:
> 
> \`2022/10/24 19:46:15 WARNING mlflow.utils.autologging\_utils: Encountered unexpected error during tensorflow autologging: INVALID\_PARAMETER\_VALUE: Changing param values is not allowed. Params were already logged='\[{'key': 'validation\_split', 'old\_value': None, 'new\_value': '0.0'}, {'key': 'shuffle', 'old\_value': None, 'new\_value': 'True'}, {'key': 'class\_weight', 'old\_value': None, 'new\_value': 'None'}, {'key': 'sample\_weight', 'old\_value': None, 'new\_value': 'None'}, {'key': 'initial\_epoch', 'old\_value': None, 'new\_value': '0'}, {'key': 'steps\_per\_epoch', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_steps', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_batch\_size', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_freq', 'old\_value': None, 'new\_value': '1'}, {'key': 'max\_queue\_size', 'old\_value': None, 'new\_value': '10'}, {'key': 'workers', 'old\_value': None, 'new\_value': '1'}, {'key': 'use\_multiprocessing', 'old\_value': None, 'new\_value': 'False'}\]' for run ID='402712a4625a43bca38c0bce38fa4ed1'.\`
> 
> As you can see, the autolog apparently logged \`None\` for all of these values. 
> 
> Again, the same script works well when I run it outside of MLproject.
> 
> \### Tracking information
> 
> \_No response\_
> 
> \### Code to reproduce issue
> 
> \`\`\`python
> """
> TF/Keras Training script for MLFlow
> """
> 
> \# mlflow run -e train\_entry --env-manager=local --experiment-name=tony-reina-experiments .
> 
> from datetime import datetime
> import os
> 
> os.environ\["TF\_CPP\_MIN\_LOG\_LEVEL"\] = "3"
> 
> import click # pip install click
> import tensorflow as tf # pip install tensorflow
> 
> \# The following import and function call,
> \# are the only additions to code required
> \# to automatically log
> \# metrics and parameters to MLflow.
> import mlflow # pip install mlflow
> 
> EXPERIMENT\_NAME = "tony-reina-experiments"
> 
> 
> def load\_data():
> """Load dataset and pre-process
> Fashion MNIST https://github.com/zalandoresearch/fashion-mnist
> 28x28 grayscale images of clothes from 10 different categories
> """
> fashion\_mnist = tf.keras.datasets.fashion\_mnist
> 
> (train\_images, train\_labels), (test\_images, test\_labels) = fashion\_mnist.load\_data()
> 
> # Normalize the images from 0.0 to 1.0
> train\_images = train\_images / 255.0
> test\_images = test\_images / 255.0
> 
> # Human-readable class names
> class\_names = \[
> "T-shirt/top",
> "Trouser",
> "Pullover",
> "Dress",
> "Coat",
> "Sandal",
> "Shirt",
> "Sneaker",
> "Bag",
> "Ankle boot",
> \]
> 
> return train\_images, train\_labels, test\_images, test\_labels, class\_names
> 
> 
> def create\_model(parameters):
> """Create a simple TensorFlow Keras model
> 
> Args:
> parameters(dict): Number of units,
> optimizer, and metrics for model
> 
> """
> 
> model = tf.keras.Sequential(
> \[
> tf.keras.layers.Flatten(input\_shape=(28, 28)),
> tf.keras.layers.Dense(parameters\["num\_units"\], activation="relu"),
> tf.keras.layers.Dense(10),
> \]
> )
> 
> model.compile(
> optimizer=tf.keras.optimizers.Adam(learning\_rate=parameters\["learning\_rate"\]),
> loss=tf.keras.losses.SparseCategoricalCrossentropy(from\_logits=True),
> metrics=\[parameters\["metrics"\]\],
> )
> 
> return model
> 
> 
> @click.command(help="The base training script for MLFlow.")
> @click.option(
> "--num-units", default=128, type=int, help="Number of units in the dense layer"
> )
> @click.option("--epochs", default=3, type=int, help="Number of training epochs")
> @click.option("--batch-size", default=32, type=int, help="Batch size")
> @click.option("--learning-rate", default=1e-4, type=float, help="Learning rate")
> @click.option("--metrics", default="accuracy", type=str, help="Model metric to track")
> @click.option(
> "--training-data", default=".", type=str, help="Path to the training data"
> )
> @click.option("--testing-data", default=".", type=str, help="Path to the testing data")
> def train(
> num\_units,
> epochs,
> batch\_size,
> learning\_rate,
> metrics,
> training\_data,
> testing\_data,
> ):
> """Run training"""
> 
> train\_images, train\_labels, test\_images, test\_labels, class\_names = load\_data()
> 
> # Instead of passing lots of variables,
> # we'll just pass a dictionary
> parameters = {
> "num\_units": num\_units,
> "num\_epochs": epochs,
> "batch\_size": batch\_size,
> "learning\_rate": learning\_rate,
> "metrics": metrics,
> "training\_data": training\_data,
> "testing\_data": testing\_data,
> }
> 
> click.secho(parameters)
> 
> click.secho("Setting up MLflow tracking uri...")
> mlflow.tracking.set\_tracking\_uri(os.environ.get("MLFLOW\_TRACKING\_URI"))
> mlflow.set\_experiment(experiment\_name=EXPERIMENT\_NAME)
> 
> mlflow.tensorflow.autolog(
> log\_models=True,
> silent=False,
> registered\_model\_name="ye\_olde\_mnist\_fashion",
> )
> 
> current\_time = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
> click.secho("Starting the MLFlow Run...")
> 
> model = create\_model(parameters)
> 
> with mlflow.start\_run(
> #run\_name=f"YeOldDemo-{current\_time}",
> tags={"ImageTag": "local"},
> description="Ye Olde Model Xample",
> ):
> 
> model.fit(
> train\_images,
> train\_labels,
> epochs=parameters\["num\_epochs"\],
> batch\_size=parameters\["batch\_size"\],
> )
> 
> click.secho("Finished training")
> 
> test\_loss, test\_acc = model.evaluate(test\_images, test\_labels)
> 
> mlflow.log\_param(key="test\_loss", value=test\_loss)
> mlflow.log\_param(key="test\_acc", value=test\_acc)
> 
> mlflow.log\_param(key="Class names", value=class\_names)
> mlflow.log\_param(key="TensorFlow version", value=tf.\_\_version\_\_)
> 
> 
> if \_\_name\_\_ == "\_\_main\_\_":
> train()
> \`\`\`
> 
> \### Stack trace
> 
> \`\`\`
> 2022/10/24 19:49:34 WARNING mlflow.utils.autologging\_utils: Encountered unexpected error during tensorflow autologging: INVALID\_PARAMETER\_VALUE: Changing param values is not allowed. Params were already logged='\[{'key': 'validation\_split', 'old\_value': None, 'new\_value': '0.0'}, {'key': 'shuffle', 'old\_value': None, 'new\_value': 'True'}, {'key': 'class\_weight', 'old\_value': None, 'new\_value': 'None'}, {'key': 'sample\_weight', 'old\_value': None, 'new\_value': 'None'}, {'key': 'initial\_epoch', 'old\_value': None, 'new\_value': '0'}, {'key': 'steps\_per\_epoch', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_steps', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_batch\_size', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_freq', 'old\_value': None, 'new\_value': '1'}, {'key': 'max\_queue\_size', 'old\_value': None, 'new\_value': '10'}, {'key': 'workers', 'old\_value': None, 'new\_value': '1'}, {'key': 'use\_multiprocessing', 'old\_value': None, 'new\_value': 'False'}\]' for run ID='a6fc78cd0973486aa6b0ddb5f36581ae'.
> \`\`\`
> 
> \### Other info / logs
> 
> \`\`\`
> 2022/10/24 19:49:34 WARNING mlflow.utils.autologging\_utils: Encountered unexpected error during tensorflow autologging: INVALID\_PARAMETER\_VALUE: Changing param values is not allowed. Params were already logged='\[{'key': 'validation\_split', 'old\_value': None, 'new\_value': '0.0'}, {'key': 'shuffle', 'old\_value': None, 'new\_value': 'True'}, {'key': 'class\_weight', 'old\_value': None, 'new\_value': 'None'}, {'key': 'sample\_weight', 'old\_value': None, 'new\_value': 'None'}, {'key': 'initial\_epoch', 'old\_value': None, 'new\_value': '0'}, {'key': 'steps\_per\_epoch', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_steps', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_batch\_size', 'old\_value': None, 'new\_value': 'None'}, {'key': 'validation\_freq', 'old\_value': None, 'new\_value': '1'}, {'key': 'max\_queue\_size', 'old\_value': None, 'new\_value': '10'}, {'key': 'workers', 'old\_value': None, 'new\_value': '1'}, {'key': 'use\_multiprocessing', 'old\_value': None, 'new\_value': 'False'}\]' for run ID='a6fc78cd0973486aa6b0ddb5f36581ae'.
> \`\`\`
> 
> \### What component(s) does this bug affect?
> 
> \- \[\] \`area/artifacts\`: Artifact stores and artifact logging
> \- \[\] \`area/build\`: Build and test infrastructure for MLflow
> \- \[\] \`area/docs\`: MLflow documentation pages
> \- \[\] \`area/examples\`: Example code
> \- \[\] \`area/model-registry\`: Model Registry service, APIs, and the fluent client calls for Model Registry
> \- \[\] \`area/models\`: MLmodel format, model serialization/deserialization, flavors
> \- \[\] \`area/pipelines\`: Pipelines, Pipeline APIs, Pipeline configs, Pipeline Templates
> \- \[X\] \`area/projects\`: MLproject format, project running backends
> \- \[\] \`area/scoring\`: MLflow Model server, model deployment tools, Spark UDFs
> \- \[\] \`area/server-infra\`: MLflow Tracking server backend
> \- \[X\] \`area/tracking\`: Tracking Service, tracking client APIs, autologging
> 
> \### What interface(s) does this bug affect?
> 
> \- \[\] \`area/uiux\`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
> \- \[\] \`area/docker\`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
> \- \[\] \`area/sqlalchemy\`: Use of SQLAlchemy in the Tracking Service or Model Registry
> \- \[\] \`area/windows\`: Windows support
> 
> \### What language(s) does this bug affect?
> 
> \- \[\] \`language/r\`: R APIs and clients
> \- \[\] \`language/java\`: Java APIs and clients
> \- \[\] \`language/new\`: Proposals for new client languages
> 
> \### What integration(s) does this bug affect?
> 
> \- \[\] \`integrations/azure\`: Azure and Azure ML integrations
> \- \[\] \`integrations/sagemaker\`: SageMaker integrations
> \- \[\] \`integrations/databricks\`: Databricks integrations

> <https://github.com/mlflow/mlflow/pull/6179>
>
> \## Related Issues/PRs
> 
> Closes #6177 
> 
> \## What changes are proposed in this p…ull request?
> 
> Fix a bug in \`mlflow server\` that causes \`SetTag\` and \`LogBatch\` requests to be erroneously rejected if empty strings are used as parameter / tag values.
> 
> \## How is this patch tested?
> 
> Added integration tests
> 
> \## Does this PR change the documentation?
> 
> \- \[X\] No. You can skip the rest of this section.
> \- \[\] Yes. Make sure the changed pages / sections render correctly by following the steps below.
> 
> 1. Check the status of the \`ci/circleci: build\_doc\` check. If it's successful, proceed to the
> next step, otherwise fix it.
> 2. Click \`Details\` on the right to open the job page of CircleCI.
> 3. Click the \`Artifacts\` tab.
> 4. Click \`docs/build/html/index.html\`.
> 5. Find the changed pages / sections and make sure they render correctly.
> 
> \## Release Notes
> 
> Fix a bug in \`mlflow server\` that causes \`SetTag\` and \`LogBatch\` requests to be erroneously rejected if empty strings are used as parameter / tag values.
> 
> \### Is this a user-facing change?
> 
> \- \[\] No. You can skip the rest of this section.
> \- \[X\] Yes. Give a description of this change to be included in the release notes for MLflow users.
> 
> (Details in 1-2 sentences. You can just refer to another PR with a description if this PR is part of a larger change.)
> 
> \### What component(s), interfaces, languages, and integrations does this PR affect?
> Components
> \- \[\] \`area/artifacts\`: Artifact stores and artifact logging
> \- \[\] \`area/build\`: Build and test infrastructure for MLflow
> \- \[\] \`area/docs\`: MLflow documentation pages
> \- \[\] \`area/examples\`: Example code
> \- \[\] \`area/model-registry\`: Model Registry service, APIs, and the fluent client calls for Model Registry
> \- \[\] \`area/models\`: MLmodel format, model serialization/deserialization, flavors
> \- \[\] \`area/pipelines\`: Pipelines, Pipeline APIs, Pipeline configs, Pipeline Templates
> \- \[\] \`area/projects\`: MLproject format, project running backends
> \- \[\] \`area/scoring\`: MLflow Model server, model deployment tools, Spark UDFs
> \- \[X\] \`area/server-infra\`: MLflow Tracking server backend
> \- \[x\] \`area/tracking\`: Tracking Service, tracking client APIs, autologging
> 
> Interface
> \- \[\] \`area/uiux\`: Front-end, user experience, plotting, JavaScript, JavaScript dev server
> \- \[\] \`area/docker\`: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
> \- \[\] \`area/sqlalchemy\`: Use of SQLAlchemy in the Tracking Service or Model Registry
> \- \[\] \`area/windows\`: Windows support
> 
> Language
> \- \[\] \`language/r\`: R APIs and clients
> \- \[\] \`language/java\`: Java APIs and clients
> \- \[\] \`language/new\`: Proposals for new client languages
> 
> Integrations
> \- \[\] \`integrations/azure\`: Azure and Azure ML integrations
> \- \[\] \`integrations/sagemaker\`: SageMaker integrations
> \- \[\] \`integrations/databricks\`: Databricks integrations
> 
> \<!--
> Insert an empty named anchor here to allow jumping to this section with a fragment URL
> (e.g. https://github.com/mlflow/mlflow/pull/123#user-content-release-note-category).
> Note that GitHub prefixes anchor names in markdown with "user-content-".
> \--\>
> \<a name="release-note-category"\>\</a\>
> \### How should the PR be classified in the release notes? Choose one:
> 
> \- \[\] \`rn/breaking-change\` - The PR will be mentioned in the "Breaking Changes" section
> \- \[\] \`rn/none\` - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
> \- \[\] \`rn/feature\` - A new user-facing feature worth mentioning in the release notes
> \- \[X\] \`rn/bug-fix\` - A user-facing bug fix worth mentioning in the release notes
> \- \[\] \`rn/documentation\` - A user-facing documentation change worth mentioning in the release notes

---

<div class="post-metadata">

**Author:** ![Petrina](https://avatars.discourse-cdn.com/v4/letter/p/a3d4f5/32.png) [@Petrina](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FPetrina)%5C
**Post date:** [November 21, 2024, 10:08am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbert-base-for-text-classification-and-mlflow%2F115601%2F3 "2024-11-21T10:08:45Z")

</div>

So, finally I found a workaround avoiding hard coding the model’s config. There is a parameter in ` AutoModelForSequenceClassification.from_pretrained()`, with which you can specify the problem type.

So in my case I used `AutoModelForSequenceClassification.from_pretrained( 'cardiffnlp/tweet_sentiment_multilingual', num_labels=3, problem_type='single_label_classification')` which sets the problem type as single\_label\_classification from the beginning and it does not create a conflict when logging to MLflow creating the issue with different values of the same parameter.

A small note here because the single\_label\_classification tag confused me in the beginning. In hugging face any problem with **one label per example** is assigned as **single\_label\_classification** problem and as **multi\_label\_classification** problem for **many labels per example**.

Thank you,  
Petrina

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsystem)%5C
**Post date:** [November 21, 2024, 10:09pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fbert-base-for-text-classification-and-mlflow%2F115601%2F4 "2024-11-21T22:09:19Z")

</div>

Closed on November 21, 2024, 10:09pm UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
