News Signals: An NLP Library for Text and Time Series (2023)

Abstract: We present an open-source Python library for building and using datasets where inputs are clusters of textual data, and outputs are sequences of real values representing one or more timeseries signals. The news-signals library supports diverse data science and NLP problem settings related to the prediction of time series behaviour using textual data feeds. For example, in the news domain, inputs are document clusters corresponding to daily news articles about a particular entity, and targets are explicitly associated real-valued timeseries: the volume of news about a particular person or company, or the number of pageviews of specific Wikimedia pages. Despite many industry and research usecases for this class of problem settings, to the best of our knowledge, News Signals is the only open-source library designed specifically to facilitate data science and research settings with natural language inputs and timeseries targets. In addition to the core codebase for building and interacting with datasets, we also conduct a suite of experiments using several popular Machine Learning libraries, which are used to establish baselines for timeseries anomaly prediction using textual inputs.

## introduction the natural ordering of many types of data along a time dimension is a consequence of the known physics of our universe. real-world applications of machine learning often involve data with implicit or explicit temporal ordering. examples include weather forecasting, market prediction, self-driving cars, and language modeling. a large body of work on time series forecasting studies models which consume and predict real-valued target signals that are explicitly ordered in time; however, aside from some existing work mainly related to market signal prediction using social media @xcite @xcite * equal contribution figure 1 : news signals datasets: clusters of documents, bucketed by time period, are associated with time series signals. ml models can be trained to predict time series signals using the textual data. @xcite @xcite @xcite , inter alia, the nlp research community has generally not focused on tasks with textual inputs and time series outputs. this is confirmed by the lack of any popular nlp tasks related to time series in resulttracking projects such as nlp-progress foot_0 and paperswith-code foot_1 . we believe there is potential for novel, impactful research into tasks beyond market signal forecasting, in which textual inputs and real-valued output signals are explicitly organized along a time dimension with fixed-length "ticks". two reasons for the lack of attention to such tasks to date may be: examples of tasks where natural language input can be used to predict a time series signal include: ## time-indexed nlp datasets traditional nlp and ml datasets consist of iid (x, y ) pairs. these pairs can be assigned indices, and be operated on by standard pre-processing procedures, such as randomly shuffling and splitting into train, dev, test subsets. however, for time series forecasting and related tasks, inputs are ordered along a time axis, and the distribution of later time steps is typically heavily dependent upon the distribution of earlier time steps; therefore, training, dev and test subsets are usually partitioned and split chronologically to reduce the potential for leakage, introducing additional complexity into data preparation. within the python data science ecosystem, libraries such as numpy @xcite , pandas (wes mckinney, 2010), and pytorch @xcite have standardized a syntax for indexing and slicing multi-dimensional matrices and dataframes along axes. when a pandas dataframe is indexed along a dimension with time-interval semantics, slicing between dates or timestamps is a very useful feature. for example, a user may want to work with the news articles and corresponding time series signals that occurred between particular start and end dates. pandas in particular includes rich tooling for indexing and slicing datasets along time-indexed axes, and news-signals delegates slice commands and indexing to pandas, exposing an interface for interacting with datasets using datetime indices foot_3 . ## the signal and signalsdataset apis signals consist of at least one time series coupled with zero or more textual data feeds. figure 2 shows an example of creating and populating a signal. because most functions on the signal class return the signal itself, users can employ a convenient chaining syntax when performing multiple operations on a signal. the library retrieves and stores the time series and news stories for the signal, and exposes a pandas-like api to the underlying dataframes. we can add arbitrary textual data feeds to signals; in figure 2, signal.sample_stories() samples stories for every day of the time series (see library documentation on github for more detailed information on how this works). signals can also be easily mapped into a single dataframe representation by using the .df property. signals' dataframe representations contain the textual and time series data associated with a signal, indexed along a datetimeindex, but they do not contain metadata such as how the signal is populated from one or more apis, and transformation semantics such as how anomalies are computed. signals automatically differentiate between textual data and time series data types -for example, when signal.plot() is called, a signal's associated time series are automatically plotted in a multi-line plot. ## building signals datasets as discussed in section 3.2, news-signals provides an api for the creation of large-scale datasets representing collections of related signals. bootstrapping datasets using wikidata the aylien newsapi links named entities in text to their wikidata ids @xcite . news-signals users can make use of the wikidata query service foot_8 to easily build new datasets starting from sparql queries that return sets of matching entities @xcite . we build the datasets for nasdaq-100, s&p 500, and us politicians in this manner, and the sparql queries used to bootstrap these entity sets are available in our repository. for the purpose of this paper, and to exemplify use of the library, we build three example datasets: nasdaq100, s&p 500, and us politicians. each of these datasets is bootstrapped from a list of wikidata entities belonging to the respective set. to retrieve the entity sets, we build a sparql query returning the set of wikidata entities that match the query, and then use this entity set to generate a dataset. this is a powerful way to generate arbitrary datasets for collections of related entities: for example, datasets for all politicians from a particular country or all american football players could be generated in this fashion. note that in some cases wikidata does not contain all entities in a particular set, for example, the nasdaq100 dataset contains fewer than 100 entities. dataset statistics are summarized in ## example models and experiments this section presents a suite of example models and experiments for users to quickly adapt to their own task settings, and to verify the utility of news-signals by establishing baselines for a straightforward anomaly prediction task. ## conclusion we have presented news-signals, an open source library for building and working with nlp datasets that predict time series signals based on textual inputs. we hope that this library can be useful to a broad group of researchers and data scientists in both academic and industry settings. naturally, we would be very happy for additional contributions from the open source community to further improve the library.