# bert_classification_model **Repository Path**: hbpiaoyi/bert_classification_model ## Basic Information - **Project Name**: bert_classification_model - **Description**: 基于Bert预训练模型的文本分类模型 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-30 - **Last Updated**: 2026-07-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README utils使用介绍 1.全局通用日志打印 导包 from utils.log import logger logger.debug("调试信息") logger.info("正常业务日志") logger.warning("警告日志") logger.error("错误信息", exc_info=True) # exc_info自动打印异常堆栈 try: 1 / 0 except Exception as e: logger.error("程序发生异常", exc_info=True) 运行结果 2026-06-30 11:28:55 | INFO | global | test.py:11 | 正常业务日志 2026-06-30 11:28:55 | WARNING | global | test.py:12 | 警告日志 2026-06-30 11:28:55 | ERROR | global | test.py:13 | 错误信息 NoneType: None 2026-06-30 11:28:55 | ERROR | global | test.py:18 | 程序发生异常 Traceback (most recent call last): File "D:\PythonCode\PythonLearn\conda3_py312\project\test.py", line 16, in 1 / 0 ~~^~~ ZeroDivisionError: division by zero 2.不同模块独立命名日志(区分哪个模块报错来源) 导包 from utils.log import get_logger img_log = get_logger("image_download") img_log.info("开始拉取镜像") file_log = get_logger("file_util") file_log.info("读取配置文件完成") 运行结果 2026-06-30 11:32:21 | INFO | image_download | test2.py:12 | 开始拉取镜像 2026-06-30 11:32:21 | INFO | file_util | test2.py:16 | 读取配置文件完成 3. data_preprocess.py load_data(path) 加载数据集, 构造数据 TextDataset(Dataset) 构建数据集对象 build_dataloader 构建数据加载器对象 4. 文件读取写入工具类 mkdir(path: str) -> None: """递归创建文件夹,不存在则创建""" exists(file_path: str) -> bool: """判断文件/文件夹是否存在""" is_file(file_path: str) -> bool: """判断是否为文件""" is_dir(dir_path: str) -> bool: """判断是否为文件夹""" get_dir(file_path: str) -> str: """获取文件所在目录""" read_text(file_path: str, encoding: str = "utf-8") -> str: """读取完整文本文件 :param file_path: 文件路径 :param encoding: 编码格式 :return: 文件全部字符串 """ read_text_lines(file_path: str, encoding: str = "utf-8", strip: bool = True) -> List[str]: """按行读取文本,返回行列表""" write_text(file_path: str, content: str, encoding: str = "utf-8", append: bool = False) -> None: """写入文本文件 :param file_path: 文件路径 :param content: 写入字符串 :param encoding: 编码 :param append: True追加写入,False覆盖 """ write_text_lines(file_path: str, lines: List[str], encoding: str = "utf-8", append: bool = False) -> None: """批量写入多行文本""" read_bytes(file_path: str) -> bytes: """读取二进制文件(图片、视频、exe等)""" write_bytes(file_path: str, data: bytes, append: bool = False) -> None: """写入二进制数据"""