Skip to main content

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

  1. 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

  1. semantic_faiss function can now take detect only copypastas based on levenshtein distance, ignoring embeddings, if "skip" is passed as argument in df_embeddings_use field.

  2. compute_bot_likelihood_metrics function can now take columns' names as arguments for more customization

  3. compute_bot_likelihood_metrics now returns high_following_followers_ratio (%), the share of rows whose following/followers ratio exceeds fw_ratio_threshold (default 10).

  4. copypasta_score_hub returns 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.

Metadata

Release files for astrodetection 0.3.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astrodetection 0.3.4
File Size Uploaded
astrodetection-0.3.4.tar.gz 59.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for astrodetection 0.3.4
File Interpreter ABI Platform
astrodetection-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 121.3 kB

Release files / astrodetection-0.3.4.tar.gz

Download URL astrodetection-0.3.4.tar.gz
Size 59.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4c9b1f8c343cc636b154a3294575c149c02ae799a5ba2235858feeab45ad21c1
BLAKE2b-256 checksum
How to use checksums
945064b0ad24fdbf3a424c6c9470236d7b80639795fb67a4a4f8fb5ab580c541
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.4-py3-none-any.whl

Download URL astrodetection-0.3.4-py3-none-any.whl
Size 61.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01cf2e74ee6c364c3d3ecf78e1de62ed6fa52cc88fa782c57764deb2914fbe05
BLAKE2b-256 checksum
How to use checksums
40cd79cf76b82a22e072d17ba5f20e8589f3a42d970529eb4b1f6c67437578cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release history Release notifications | RSS feed

0.3.6

2 release files

0.3.5

2 release files

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page