class_docstr: A wrapper class to apply sklearn clustering models on DocumentEmbeddings.
class_docstr_tok: ["A","wrapper","class","to","apply","sklearn","clustering","models","on","DocumentEmbeddings","."]
docstr: Makes a flair-corpus sklearn compatible.
  
  Turns the corpora into X, y datasets as required for most sklearn clustering models.
  Ref.: https://scikit-learn.org/stable/modules/classes.html#module-sklearn.cluster
docstr_tok: ["Makes","a","flair-corpus","sklearn","compatible",".","Turns","the","corpora","into","X",",","y","datasets","as","required","for","most","sklearn","clustering","models",".","Ref",".",":","https",":","\/\/scikit-learn.org\/stable\/modules\/classes.html","#","module-sklearn.cluster"]
code: def _convert_dataset(
      self,
      corpus,
      label_type: Optional[str] = None,
      batch_size: int = 32,
      return_label_dict: bool = False,
  ):
      """Makes a flair-corpus sklearn compatible.
  
      Turns the corpora into X, y datasets as required for most sklearn clustering models.
      Ref.: https://scikit-learn.org/stable/modules/classes.html#module-sklearn.cluster
      """
      log.info("Embed sentences...")
      sentences = []
      for batch in tqdm(
          DataLoader(corpus.get_all_sentences(), batch_size=batch_size)
      ):
          self.embeddings.embed(batch)
          sentences.extend(batch)
  
      X = [
          sentence.embedding.cpu().detach().numpy()
          for sentence in sentences
      ]
  
      if label_type is None:
          return X
  
      labels = [
          sentence.get_labels(label_type)[0].value
          for sentence in sentences
      ]
      label_dict = {
          v: k for k, v in enumerate(OrderedDict.fromkeys(labels))
      }
      y = [label_dict.get(label) for label in labels]
  
      if return_label_dict:
          return X, y, label_dict
  
      return X, y
  
imports: import logging
  import pickle
  from collections import OrderedDict
  from pathlib import Path
  from typing import Optional, Union
  import joblib
  from sklearn.base import BaseEstimator, ClusterMixin
  from sklearn.metrics import normalized_mutual_info_score
  from tqdm import tqdm
  from flair.data import Corpus, _iter_dataset
  from flair.datasets import DataLoader
  from flair.embeddings import DocumentEmbeddings
label_desc: Use image node_id 6 for calling the ClusteringModel obj's underlying member method code with example usage: obj._convert_dataset(corpus, label_type, batch_size, return_label_dict) and returns: X,  y, X, X,  y,  label_dict