Instructions to use ctheodoris/Geneformer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ctheodoris/Geneformer with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="ctheodoris/Geneformer")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("ctheodoris/Geneformer") model = AutoModelForMaskedLM.from_pretrained("ctheodoris/Geneformer", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
Download geneformer/mtl/optuna_utils.py from ctheodoris/Geneformer: direct link, hf CLI and curl.
- Browser
- Download file 850 Bytes
-
https://huggingface.co/ctheodoris/Geneformer/resolve/9f0fa5d773efa20d201f2d548baff6edca7d08d5/geneformer/mtl/optuna_utils.py
- Command line
-
hf download hf://ctheodoris/Geneformer@9f0fa5d773efa20d201f2d548baff6edca7d08d5/geneformer/mtl/optuna_utils.py
-
curl -L -o optuna_utils.py https://huggingface.co/ctheodoris/Geneformer/resolve/9f0fa5d773efa20d201f2d548baff6edca7d08d5/geneformer/mtl/optuna_utils.py
850 Bytes
| import optuna | |
| from optuna.integration import TensorBoardCallback | |
| def save_trial_callback(study, trial, trials_result_path): | |
| with open(trials_result_path, "a") as f: | |
| f.write( | |
| f"Trial {trial.number}: Value (F1 Macro): {trial.value}, Params: {trial.params}\n" | |
| ) | |
| def create_optuna_study(objective, n_trials, trials_result_path, tensorboard_log_dir): | |
| study = optuna.create_study(direction="maximize") | |
| # init TensorBoard callback | |
| tensorboard_callback = TensorBoardCallback( | |
| dirname=tensorboard_log_dir, metric_name="F1 Macro" | |
| ) | |
| # callback and TensorBoard callback | |
| callbacks = [ | |
| lambda study, trial: save_trial_callback(study, trial, trials_result_path), | |
| tensorboard_callback, | |
| ] | |
| study.optimize(objective, n_trials=n_trials, callbacks=callbacks) | |
| return study | |