Astrodetection
Astrodetection is a Python library designed for detecting astroturfing clues from lists of posts (mainly on X up to now, but not exclusively)
Installation
Pip
pip install "astrodetection[standard]"
or
pip install "astrodetection[light]"
Conda
-
Use the YAML file to configure the environment with conda:
conda create -n astrodetection_env conda activate astrodetection_env conda env update -f environment_standard.yml
Note: the environment_standard.yml configuration file uses FAISS and Fasttext libraries for VIGINUM D3LTA implementation
**If you have compatibility issues, prefer environment_light.yml and use astrodetection_light module
Usage
You can import directly the main functions:
from astrodetection import semantic_faiss, prepare_input_data, compute_bot_likelihood_metrics, create_network, copypasta_score_hub
Or use them directly:
import glob
import pandas as pd
import os
import numpy as np
import astrodetection
# Load a single JSON file into a DataFrame
file = "file_path" # Select the first file
df = pd.read_json(file)
df.index = df.index.astype(str) # Compatibility with d3lta
# Preprocess the DataFrame
df = df[df['tweet'].str.len() > 100]
df = df[df['username'] != 'grok']
df.index = df.index.astype(str)
# Compute matches and scores
df_filtered, df_emb = astrodetection.prepare_input_data(df, embeddings=df['emb'])
matches, df_cluster = astrodetection.semantic_faiss(
df_filtered.rename(columns={'tweet': 'original'}),
min_size_txt=0,
df_embeddings_use=df_emb,
threshold_grapheme=0.8,
threshold_language=0.715,
threshold_semantic=0.9
) #function taken from D3LTA
# Create the raw post-similarity network and measure its largest component
network = astrodetection.create_network(matches, df, return_sigma=False)
copypasta_hub = astrodetection.copypasta_score_hub(network, df)
# The same indicator is also available in the combined metrics
scores = astrodetection.compute_bot_likelihood_metrics(
df,
matches=matches,
G_copypasta=network,
)
# Create the interactive visualization when needed
network_viz = astrodetection.create_network(matches, df)
New changes
-
semantic_faissfunction can now take detect only copypastas based on levenshtein distance, ignoring embeddings, if "skip" is passed as argument in df_embeddings_use field. -
compute_bot_likelihood_metricsfunction can now take columns' names as arguments for more customization -
compute_bot_likelihood_metricsnow returnshigh_following_followers_ratio (%), the share of rows whose following/followers ratio exceeds fw_ratio_threshold (default 10). -
copypasta_score_hubreturns the percentage of all original posts belonging to the largest connected component of a post-similarity network. By default it retains every duplicate type and every edge already present in the network.
Release files for astrodetection 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| astrodetection-0.3.2.tar.gz | 59.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| astrodetection-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 120.1 kB
Release files / astrodetection-0.3.2.tar.gz
| Download URL | astrodetection-0.3.2.tar.gz |
|---|---|
| Size | 59.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ed2bef606d4a35fff4686919d7128bca57d03c5b2dc4dc1e7c44f2b89c16e20
|
|
BLAKE2b-256 checksum How to use checksums |
7ef95882834714b5d5c1de1398db953ee58705d18c82c5bf93013b00304a044c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|
Release files / astrodetection-0.3.2-py3-none-any.whl
| Download URL | astrodetection-0.3.2-py3-none-any.whl |
|---|---|
| Size | 60.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b13663047d09f0334650d5c26d07a55d03f408ace4ff0e921bd115f5c4f9597e
|
|
BLAKE2b-256 checksum How to use checksums |
4909d926c90ff541b861ac4afab2b36a2f357d734b7d0bbcdad358b4d21bf96f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.4
|