Bootstrap

小红书笔记主题分析

# -*- coding: UTF-8 -*-
import numpy as np
import argparse
import random
import pickle as pk
import json


def save_json(file, res):
    """
    保存 dict 到本地json 文件 , 自动创建json
    :param file: json 文件名
    :param res: 数据
    :return:
    """
    with open(file, 'w', encoding='utf-8') as wr:
        json.dump(res, wr, ensure_ascii=False, indent=2)


def load_json(file):
    """
    读取本地json文件,得到dict
    :param file: json 文件名
    :return:
    """
    with open(file, 'r', encoding='utf-8') as reader:
        res = json.load(reader)
    return res


def save_cache(file, ob):
    wr = open(file, 'wb')
    pk.dump(ob, wr)
    wr.close()


def load_cache(file):
    re = open(file, 'rb')
    ob = pk.load(re)
    re.close()
    return ob

def read_vectors(path, topn):  # read top n word vectors, i.e. top is 10000
    lines_num, dim = 0, 0
  
;