def truncate_subwords(doc_sents, max_subwords, bpe, sep_symb):
    """Truncates subwords of the doc` to fit `max_subwords` budget.
    The budget includes subwords of `sep_symb`. And `doc` is internally mapped
    to subwords.

    Args:
         doc_sents: list of sentence strings (words).
         max_subwords: the allowed budget in subwords.
         bpe: fairseq bpe encoder.
         sep_symb: separation symbol with padding.
    Returns:
        list of (word) sentence strings.
    """
    assert " " in sep_symb
    # mapping the document sentences to BPEs
    doc_str = f"{sep_symb} ".join(doc_sents)
    doc_bpe = bpe.encode(doc_str)
    doc_bpe_symb = bpe.encode(sep_symb)
    doc_bpe_sents = [s.strip() for s in doc_bpe.split(doc_bpe_symb)]

    # selecting sentences that fit the budget
    coll = []
    curr_len = 0
    for indx, sent in enumerate(doc_bpe_sents):
        bpe_sent_len = len(sent.split())
        # adding offset to all but the first sentence
        if indx > 0:
            bpe_sent_len += len(doc_bpe_symb.split())
        if bpe_sent_len <= max_subwords - curr_len:
            coll.append(bpe.decode(sent).strip())
            curr_len += bpe_sent_len
        else:
            break

    # sanity check
    # act_len = len(bpe.encode(f" {sep_symb} ".join(coll)).split())
    # assert act_len == curr_len

    return coll