LLM-based system for extracting main events from news articles
Project description
LLM-5W1H
This project is a LLM-based System for extracting main events from news articles.
Step-by-Step Tutorial on how to use News Analyzer API
-
Ensure you have OpenAI's Python library installed by running the following command in the Python shell.
pip install openai -
Import News Analyzer API.
from src.NewsAnalyzerAPI import NewsArticle
from src.NewsAnalyzerAPI import LLMConnector
from src.NewsAnalyzerAPI import NewsAnalyzer
- Instantiate your LLMConnector and NewsAnalyzer objects.
connector = LLMConnector("your_llm_endpoint", "your_llm_key", "your_llm_model")
analyzer = NewsAnalyzer(connector)
- Give an example article to the analyzer, with the following parameters: title, description, text, date, url.
title = "Taliban attacks German consulate in northern Afghan city of Mazar-i-Sharif with truck bomb"
description = "The death toll from a powerful Taliban truck bombing at the German consulate in Afghanistan's Mazar-i-Sharif city rose to at least six Friday, with more than 100 others wounded in a major militant assault."
text = "The death toll from a powerful Taliban truck bombing at the German consulate in Afghanistan's Mazar-i-Sharif city rose to at least six Friday, with more than 100 others wounded in a major militant assault. The Taliban said the bombing late Thursday, which tore a massive crater in the road and overturned cars, was a \"revenge attack\" for US air strikes this month in the volatile province of Kunduz that left 32 civilians dead. The explosion, followed by sporadic gunfire, reverberated across the usually tranquil northern city, smashing windows of nearby shops and leaving terrified local residents fleeing for cover. \"The suicide attacker rammed his explosives-laden car into the wall of the German consulate,\" local police chief Sayed Kamal Sadat told AFP. All German staff from the consulate were unharmed, according to the foreign ministry in Berlin."
date = "2016-11-11 08:42:13"
url = "http://www.telegraph.co.uk/news/2016/11/10/taliban-attack-german-consulate-in-northern-afghan-city-of-mazar/"
article_example = NewsArticle(title, description, text, date, url)
- Extract the article components by calling process_article(article) function (or process_articles(articles) for a list of articles) in the created NewsAnalyzer object:
analyzer.process_article(article_example)
This function extracts all of the article components: what, where, when, who, why, how (5W1H). It is also possible to extract each of them separately by calling the function identify_component(article, component) in the same NewsAnalyzer object, where the 'component' parameter must be one of the components from 5W1H. For example:
analyzer.identify_component(article_example, 'what')
This line returns the 'what' component from the article as a result.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm5w1h-0.0.1.tar.gz.
File metadata
- Download URL: llm5w1h-0.0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23f497d6820f7d3ad2a3e33fb4eccde40420b516b93715672b59d3dcdc10c2ce
|
|
| MD5 |
d85ae614fd7d0d41c9a43e7df8b53cf0
|
|
| BLAKE2b-256 |
a2c38acd19a213335b60f8797ccc36e4876f25a38f9e1b057a06d4d3fb2c9dd6
|
File details
Details for the file llm5w1h-0.0.1-py3-none-any.whl.
File metadata
- Download URL: llm5w1h-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96dcf1689b1a0d8f5a1bbbed701985530c1df7c8f880f8aa1e4bc08d0e034dce
|
|
| MD5 |
a0b8788fe2dfc8622bd260f053e315c7
|
|
| BLAKE2b-256 |
e3401d1780a0877d3dee7e9027ea45f31d43993b146fe7293a9e9228f4ccd1d9
|