There is no redundancy in your code: you read the file once and each time offer each sentence and each marked word exactly once. Regardless of how you write your code (for example, using concepts), you will hide only nested loops, and not skip any processing.
The only potential for improvement is the complexity of the space: instead of immediately reading the entire file, you can read it in steps. But since you need to process entire sentences at a time, it is not as simple as reading and processing one line at a time; therefore, I would not worry if your files were not whole gigabytes; for short files this will not make any difference.
In short, your loops are fine. There is something or something in the code that you could clear (for example, an if clause that matches POS tags), but that won't change anything useful.
source share