def prepare_global_logging(params) -> None: """ This function configures 3 global logging attributes - streaming stdout and stderr to a file as well as the terminal, setting the formatting for the python logging library and setting the interval frequency for the Tqdm progress bar. Note that this function does not set the logging level, which is set in ``allennlp/run.py``. Parameters ---------- serializezation_dir : ``str``, required. The directory to stream logs to. file_friendly_logging : ``bool``, required. Whether logs should clean the output to prevent carridge returns (used to update progress bars on a single terminal line). """ serialization_dir = params['serialization_dir'] file_friendly_logging = params['file_friendly_logging'] Tqdm.set_slower_interval(file_friendly_logging) std_out_file = os.path.join(serialization_dir, "stdout.log") sys.stdout = TeeLogger( std_out_file, # type: ignore sys.stdout, file_friendly_logging) sys.stderr = TeeLogger( os.path.join(serialization_dir, "stderr.log"), # type: ignore sys.stderr, file_friendly_logging) logging.init_logger(log_file=std_out_file)
import re import json from collections import defaultdict, Counter import penman import networkx as nx from stog.data.vocabulary import DEFAULT_PADDING_TOKEN, DEFAULT_OOV_TOKEN from stog.data.dataset_readers.amr_parsing.graph_repair import GraphRepair from stog.utils.string import find_similar_token, is_abstract_token, is_english_punct from stog.utils import logging logger = logging.init_logger() # Disable inverting ':mod' relation. penman.AMRCodec._inversions.pop('domain') penman.AMRCodec._deinversions.pop('mod') from penman import Triple amr_codec = penman.AMRCodec(indent=6) WORDSENSE_RE = re.compile(r'-\d\d$') QUOTED_RE = re.compile(r'^".*"$') class AMR: def __init__(self, id=None, sentence=None, graph=None, tokens=None,
""" Adopted from AllenNLP: https://github.com/allenai/allennlp/tree/v0.6.1/allennlp/common Functions and exceptions for checking that AllenNLP and its models are configured correctly. """ from torch import cuda from stog.utils import logging logger = logging.init_logger() # pylint: disable=invalid-name class ConfigurationError(Exception): """ The exception raised by any AllenNLP object when it's misconfigured (e.g. missing properties, invalid properties, unknown properties). """ def __init__(self, message): super(ConfigurationError, self).__init__() self.message = message def __str__(self): return repr(self.message) def log_pytorch_version_info(): import torch