Skip to main content

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

  1. Ensure you have OpenAI's Python library installed by running the following command in the Python shell.

     pip install openai 
    
  2. Import News Analyzer API.

from src.NewsAnalyzerAPI import NewsArticle
from src.NewsAnalyzerAPI import LLMConnector
from src.NewsAnalyzerAPI import NewsAnalyzer
  1. Instantiate your LLMConnector and NewsAnalyzer objects.
connector = LLMConnector("your_llm_endpoint", "your_llm_key", "your_llm_model")
analyzer = NewsAnalyzer(connector)
  1. 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)
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm5w1h-0.0.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm5w1h-0.0.2-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file llm5w1h-0.0.2.tar.gz.

File metadata

  • Download URL: llm5w1h-0.0.2.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

Hashes for llm5w1h-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a88404744e419c11397902b56b64aca65daa3cd0c0d06a3efbc7268518958456
MD5 474a76de7f44a3834e23337bdc68da6c
BLAKE2b-256 afac8eaa592e5c187cbd17497195aa7c26545391332958ff78594e207e543c7e

See more details on using hashes here.

File details

Details for the file llm5w1h-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: llm5w1h-0.0.2-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

Hashes for llm5w1h-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fcea2ec8fae637909e9683863bda9b823cfa290f331d0f10840f512ff61a9d2d
MD5 2b40cf60f7b64e30b4e2df826e985d28
BLAKE2b-256 c7e14b9501fba73e931ce359ebf7b1c37da36aab225dce4384f8a0556868daa5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page