terra.gene_embed_dataset

terra.gene_embed_dataset#

terra.gene_embed_dataset(dataset, model_folder_path, emb_layer=None, cell_gene_ids=[], neighborhood_gene_ids=[], batch_size=128, pin_memory=False, num_workers=12, return_gene=False, return_gene_per_data=False, compute_cosine_with_list=[], return_distance=False, return_cosine_sim=False, return_receptor_average=False, include_spatial_cell_emb=True, description='', ignore_spc_tokens=True)#

Compute per-gene cell and neighborhood embeddings (and optional cosine-similarity / EMD statistics) over a tokenized dataset.

Parameters:
  • dataset (Dataset) – Tokenized Hugging Face dataset.

  • model_folder_path (str) – Path to the folder containing the model config, token dictionary, and normalization factors.

  • emb_layer (Optional[int] (default: None)) – Layer for which to retrieve the embedding.

  • cell_gene_ids (list (default: [])) – List with gene IDs for which cell gene embeddings will be retrieved.

  • neighborhood_gene_ids (list (default: [])) – List with gene IDs for which neighborhood gene embeddings will be retrived.

  • batch_size (int (default: 128)) – Dataloader param.

  • pin_memory (bool (default: False)) – Dataloader param.

  • num_workers (int (default: 12)) – Number of workers used.

  • return_gene_per_data (bool (default: False)) – If True will return gene_embedding for each gene per dataset.

  • compute_cosine_with_list (list[str] (default: [])) – A list that defines the items with which we want to compute cosine similarity. It could have value of cell or/and neighborhood.

  • return_distance (bool (default: False)) – If True will compute and return distance between cosine sim of cell_neb and cell_cell matrix.

  • return_cosine_sim (bool (default: False)) – If True will compute and return cosine_sim matrix.

  • return_receptor_average (bool (default: False)) – If True will compute and return receptor average embeddings for cell-neighborhood gene pairs.

  • include_spatial_cell_emb (bool (default: True)) – If True, also return gene embeddings for spatially contextualized cell embedding that attends to the neighborhood.

  • description (str (default: '')) – Description for task that is currently using this function.

Return type:

dict

Returns:

output_embed: Dictionary with the cell, cell gene, neighborhood, and neighborhood gene embeddings.