# Access feature in custom compute\_loss method

**URL:** <https://discuss.huggingface.co/t/access-feature-in-custom-compute-loss-method/81785>\
**Category:** 🤗Transformers\
**Created:** [April 15, 2024, 6:43am UTC](https://discuss.huggingface.co/t/access-feature-in-custom-compute-loss-method/81785 "2024-04-15T06:43:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mochmoch](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mochmoch](https://discuss.huggingface.co/u/mochmoch)\
**Post date:** [April 15, 2024, 6:43am UTC](https://discuss.huggingface.co/t/access-feature-in-custom-compute-loss-method/81785/1 "2024-04-15T06:43:50Z")

</div>

I’m running into a Hugging Face issue when fine-tuning a model and want to access other features during my custom `compute_loss` function. However, I am unable to access these in the `inputs` object passed into the `compute_loss` function, even though the train\_dataset I pass into my CustomTrainer includes this feature. When I call `trainer.train()`, I get the following error.

```auto
---> z = inputs.pop("feature_a")
KeyError: 'feature_a'

```

I made sure that the `train_dataset` passed into my CustomTrainer includes “feature\_a”, as well as include `remove_unused_columns=False` in the TrainingArguments and implement `data_collator` that returns `{"input_ids": input_ids, "attention_mask": attention_mask, "labels": labels, "feature_a": feature_a}`.

Is it possible to access additional features (other than `labels` and `input_ids`) in a custom `compute_loss` function and if so, what I should do to fix this issue of the feature not being in the `inputs` object passed into `compute_loss`?
