def replace_bigrams(textdict, bigrams):
    """
    replace bigrams in the texts
    Input:
        - textdict: a dict with {docid: preprocessed_text}
        - bigrams: for bigrams scores
    Returns:
        - textdict: the same texts but preprocessed and with all bigrams joined as "word1_word2"
    """
    docids = set(textdict.keys())
    for did in docids:
        text = textdict[did]
        for bigram in bigrams:
            if bigram in text:
                text = text.replace(bigram, '%s_%s' % tuple(bigram.split()))
        textdict[did] = text
    return textdict
