Repository: mlflow/mlflow

Issue:
[BUG]mlflow.log_input will export dataset to json and import dataset again
### Issues Policy acknowledgement

- [X] I have read and agree to submit bug reports in accordance with the [issues policy](https://www.github.com/mlflow/mlflow/blob/master/ISSUE_POLICY.md)

### Where did you encounter this bug?

Local machine

### Willingness to contribute

No. I cannot contribute a bug fix at this time.

### MLflow version

- Client: 2.11.3
- Tracking server: 2.11.3


### System information

- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Ubuntu 18.04 (WSL2)
- **Python version**: 3.10


### Describe the problem

run `mlflow.log_input(dataset, context='training')` will export dataset to json and import dataset again

`mlflow.log_input(dataset, context='training')` will call
`dataset_input = DatasetInput(dataset=dataset._to_mlflow_entity(), tags=tags_to_log)` will cal
```
def _to_mlflow_entity(self) -> DatasetEntity:
    """
    Returns:
        A `mlflow.entities.Dataset` instance representing the dataset.
    """
    dataset_json = json.loads(self.to_json())
    return DatasetEntity(
        name=dataset_json["name"],
        digest=dataset_json["digest"],
        source_type=dataset_json["source_type"],
        source=dataset_json["source"],
        schema=dataset_json.get("schema"),
        profile=dataset_json.get("profile"),
    )
```
`dataset_json = json.loads(self.to_json())` will export dataset to json and import dataset again


Dataset dinifination
```
class MyDataset(Dataset):
    def __init__(self, data_dir, segment_len=128):
        self.data_dir = data_dir
        self.segment_len = segment_len

        # Load the mapping from speaker name to their corresponding id.
        mapping_path = Path(data_dir) / "mapping.json"
        mapping = json.load(mapping_path.open())
        self.speaker2id = mapping["speaker2id"]

        # Load metadata of training data.
        metadata_path = Path(data_dir) / "metadata.json"
        metadata = json.load(open(metadata_path))["speakers"]

        # Get the total number of speaker.
        self.speaker_num = len(metadata.keys())
        self.data = []
        for speaker in metadata.keys():
            for utterances in metadata[speaker]:
                self.data.append([utterances["feature_path"], self.speaker2id[speaker]])
```


### Tracking information

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```shell
REPLACE_ME
```


### Code to reproduce issue

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
class MyDataset(Dataset):
    def __init__(self, data_dir, segment_len=128):
        self.data_dir = data_dir
        self.segment_len = segment_len

        # Load the mapping from speaker name to their corresponding id.
        mapping_path = Path(data_dir) / "mapping.json"
        mapping = json.load(mapping_path.open())
        self.speaker2id = mapping["speaker2id"]

        # Load metadata of training data.
        metadata_path = Path(data_dir) / "metadata.json"
        metadata = json.load(open(metadata_path))["speakers"]

        # Get the total number of speaker.
        self.speaker_num = len(metadata.keys())
        self.data = []
        for speaker in metadata.keys():
            for utterances in metadata[speaker]:
                self.data.append([utterances["feature_path"], self.speaker2id[speaker]])

        # Create a DataFrame from the data
        df = pd.DataFrame(self.data, columns=['feature_path', 'speaker_id'])
        # Create a Dataset object from the DataFrame
        dataset = mlflow.data.from_pandas(df, source=data_dir)
        # Log the Dataset object
        mlflow.log_input(dataset, context='training')

dataset = MyDataset("./Dataset")
```

Data is [here](https://drive.google.com/drive/folders/1vI1kuLB-q1VilIftiwnPOCAeOOFfBZge?usp=sharing)


### Stack trace

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
REPLACE_ME
```


### Other info / logs

<!-- PLEASE KEEP BACKTICKS AND CHECK PREVIEW -->
```
REPLACE_ME
```


### What component(s) does this bug affect?

- [X] `area/artifacts`: Artifact stores and artifact logging
- [ ] `area/build`: Build and test infrastructure for MLflow
- [ ] `area/deployments`: MLflow Deployments client APIs, server, and third-party Deployments integrations
- [ ] `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/recipes`: Recipes, Recipe APIs, Recipe configs, Recipe Templates
- [ ] `area/projects`: MLproject format, project running backends
- [ ] `area/scoring`: MLflow Model server, model deployment tools, Spark UDFs
- [ ] `area/server-infra`: MLflow Tracking server backend
- [ ] `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


Discussion:

Resolving patch:
diff --git a/mlflow/data/dataset.py b/mlflow/data/dataset.py
--- a/mlflow/data/dataset.py
+++ b/mlflow/data/dataset.py
@@ -113,12 +113,12 @@ def _to_mlflow_entity(self) -> DatasetEntity:
         Returns:
             A `mlflow.entities.Dataset` instance representing the dataset.
         """
-        dataset_json = json.loads(self.to_json())
+        dataset_dict = self.to_dict()
         return DatasetEntity(
-            name=dataset_json["name"],
-            digest=dataset_json["digest"],
-            source_type=dataset_json["source_type"],
-            source=dataset_json["source"],
-            schema=dataset_json.get("schema"),
-            profile=dataset_json.get("profile"),
+            name=dataset_dict["name"],
+            digest=dataset_dict["digest"],
+            source_type=dataset_dict["source_type"],
+            source=dataset_dict["source"],
+            schema=dataset_dict.get("schema"),
+            profile=dataset_dict.get("profile"),
         )


Test patch: