<SYSTEM_TASK:>
Given the following text problem statement, write Python code to implement the functionality described below in problem statement
<END_TASK>
<USER_TASK:>
Problem:
How to batch convert sentence lengths to masks in PyTorch?
<ASSISTANT_TASK:>
Python Code:
import numpy as np
import pandas as pd
import torch
lens = load_data()
max_len = max(lens)
mask = torch.arange(max_len).expand(len(lens), max_len) < lens.unsqueeze(1)
mask = mask.type(torch.LongTensor)
<END_TASK>