Abstract
Twitter has grown to become an important platform to access immediate information about major events and dynamic topics. As one example, recent work has shown that classifiers trained to detect topical content on Twitter can generalize well beyond the training data. Since access to Twitter data is hidden behind a limited search API, it is impossible (for most users) to apply these classifiers directly to the Twitter unfiltered data streams ("firehose"). Rather, applications must first decide what content to retrieve through the search API before filtering that content with topical classifiers. Thus, it is critically important to query the Twitter API relative to the intended topical classifier in a way that minimizes the amount of negatively classified data retrieved. In this paper, we propose a sequence of query optimization methods that generalize notions of the maximum coverage problem to find the subset of query terms within the API limits that cover most of the topically relevant tweets without sacrificing precision. We evaluate the proposed methods on a large dataset of Twitter data collected during 2013 and 2014 labeled using manually curated hashtags for eight topics. Among many insights, our analysis shows that the best of the proposed methods can significantly outperform the firehose on precision and F1-score while achieving high recall within strict API limitations.
Introduction
For researchers and developers, Twitter is a goldmine of real-time data. However, access remains a major hurdle. While the "firehose" provides every single tweet, it is often prohibitively expensive or restricted. Most users rely on the free Search API, which imposes strict rate limits and constraints on query length (e.g., 500 characters).
This creates a classic retrieval trade-off. Specific keywords (like #BlackLivesMatter) provide high precision but low recall, missing many related tweets. Conversely, broad terms (like protesters) provide high recall but drown the system in irrelevant noise, quickly exhausting API bandwidth. This research seeks the "Goldilocks" zone: selecting the optimal $K$ keywords to maximize the retrieval of relevant content without wasting API resources on "noise."
Methods
The researchers proposed a two-stage framework to bridge the gap between limited API access and full-stream classification.
- Stage 1 (Retrieval): Use an optimized query to pull data from the Search API.
- Stage 2 (Classification): Use a pre-trained machine learning classifier to rank the retrieved tweets.
To optimize Stage 1, query selection was formulated as an Integer Linear Programming (ILP) problem, specifically a variation of the Maximum K-Coverage Problem. Three novel formulations were compared:
- CILP (Coverage-based): Selects keywords that cover as many relevant ("positive") tweets as possible.
- WILP (Weighted): Weights keywords based on their Mutual Information with the topic.
- CAILP (Coverage/Anti-coverage): The most advanced model, which rewards covering relevant tweets while explicitly penalizing keywords that retrieve irrelevant ("negative") data.
Because solving ILPs exactly is computationally expensive (NP-hard), the authors also implemented a Greedy Approximation algorithm for real-time feasibility.
Experimental Setup
The study utilized a massive dataset of 135,910,871 English tweets from 2013–2014. Ground truth was established across seven distinct topics (e.g., Natural Disasters, Social Issues, Space, Health) using human-curated labeling hashtags. This labeled set allowed the researchers to simulate the "firehose" and evaluate how well their optimized API queries performed against the full dataset.
Results and Discussion
The evaluation demonstrated that knowing what not to retrieve is as critical as knowing what to retrieve. By penalizing keywords that bring in irrelevant data, CAILP achieved a massive jump in precision compared to models focusing only on positive coverage.
Key findings include:
- Data Efficiency: CAILP typically retrieved fewer than 900,000 tweets out of a 96-million-tweet firehose (less than 1%), staying well within API limits.
- Precision Boost: In the "Social Issues" topic, CAILP achieved a precision of 0.720, a significant improvement over the standard "Top-K" keyword baseline of 0.086.
- Ranking Quality: Using Precision@100, CAILP matched or outperformed the firehose-based classifier across almost all topics.
- Computational Speed: While the optimal Gurobi solver took over 80 minutes for large datasets, the greedy algorithm finished in seconds with negligible loss in performance.
Conclusion
The CAILP method demonstrates that intelligent query optimization can effectively mimic the performance of the Twitter firehose using only the limited Search API. While the current method is "offline" (based on historical data), it provides a robust foundation for future dynamic query reformulation as topics evolve in real-time.
Summary updated