# AttributeError for Text Dataset For Next Sentence Prediction: no attribute 'documents'

**URL:** <https://discuss.huggingface.co/t/attributeerror-for-text-dataset-for-next-sentence-prediction-no-attribute-documents/8687>\
**Category:** Beginners\
**Created:** [July 26, 2021, 10:46am UTC](https://discuss.huggingface.co/t/attributeerror-for-text-dataset-for-next-sentence-prediction-no-attribute-documents/8687 "2021-07-26T10:46:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![llaurabat](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@llaurabat](https://discuss.huggingface.co/u/llaurabat)\
**Post date:** [July 26, 2021, 10:46am UTC](https://discuss.huggingface.co/t/attributeerror-for-text-dataset-for-next-sentence-prediction-no-attribute-documents/8687/1 "2021-07-26T10:46:48Z")

</div>

Hello,

I am preparing some data for BERT fine-tuning for Next Sentence Prediction.  
In my understanding, the way to go is:

1. Pass the data through the `TextDatasetForNextSentencePrediction` class
2. Instantiate `DataCollatorForLanguageModeling` (as DataCollatorForNextSentencePrediction has been removed)
3. Pass both to the Trainer

However, there seems to be some bug with the attribute `documents` to the class `TextDatasetForNextSentencePrediction`. Indeed, while for some runs the attribute is produced, for others I get `AttributeError: 'TextDatasetForNextSentencePrediction' object has no attribute 'documents'` reporting that the attribute is missing.  
I also see a warning saying that soon enough this code will be replaced. I was thus wondering whether this is still the pipeline you suggest or I should go another way.

Below sample data and minimal code to reproduce the error.

![Screenshot 2021-07-26 at 12.38.50](https://us1.discourse-cdn.com/hellohellohello/original/2X/7/713be9bdf86424c67daf407fad7350d423ac3edb.png)

```auto
from transformers.data.datasets.language_modeling import TextDatasetForNextSentencePrediction
from transformers import BertTokenizerFast

tokenizer = BertTokenizerFast.from_pretrained('bert-base-cased')
train_dataset = TextDatasetForNextSentencePrediction(
    tokenizer=tokenizer,
    file_path="test.txt",
    block_size=512,
)

docs = train_dataset.documents

```
