def fetch_buffer(self, idx, reset=True):
        """Fetch sentences from the file into the buffer.

        Args:
            idx(int): Index used to fetch the sentences.
            reset(bool): If need to reset the contents of the current buffer.

        """
        # Reset the contents of the current buffer.
        if reset:
            self.src[idx]["data"] = []
            self.trg[idx]["data"] = []

        # Populate buffer
        for src, trg in zip(self.f_src[idx], self.f_trg[idx]):
            if len(self.src[idx]["data"]) == self.buffer_size:
                break
            if self.lowercase:
                self.src[idx]["data"].append(src.lower().split())
                self.trg[idx]["data"].append(trg.lower().split())

            else:
                self.src[idx]["data"].append(src.split())
                self.trg[idx]["data"].append(trg.split())

        # Sort sentences by decreasing length (hacky bucketing)
        self.src[idx]["data"], self.trg[idx]["data"] = zip(
            *sorted(
                zip(self.src[idx]["data"], self.trg[idx]["data"]),
                key=lambda x: len(x[0]),
                reverse=True,
            )
        )

        """If buffer isn't full after reading the contents of the file,
        cycle around. """
        if len(self.src[idx]["data"]) < self.buffer_size:
            assert len(self.src[idx]["data"]) == len(self.trg[idx]["data"])
            # Cast things to list to avoid issue with calling .append above
            self.src[idx]["data"] = list(self.src[idx]["data"])
            self.trg[idx]["data"] = list(self.trg[idx]["data"])
            self._reset_filepointer(idx)
            self.fetch_buffer(idx, reset=False)
Fetch sentences from the file into the buffer.

        Args:
            idx(int): Index used to fetch the sentences.
            reset(bool): If need to reset the contents of the current buffer.

        
utils_nlp/models/gensen/utils.py