Ethical Manifolds is a project that aims to analyze and classify text based on ethical dimensions using deep learning.
The project uses a modular architecture with the following main components:
- EthicalManifold: The main class that orchestrates the entire process.
- EmbeddingManager: Handles text tokenization and embedding using FastText.
- ClassifierManager: Manages multiple ethical dimension classifiers.
- EthicalClassifierModel: The neural network model for classification.
Here's a high-level overview of the architecture:
graph TD;
A[train_and_test.py] --> B[EthicalManifold]
B --> C[EmbeddingManager]
B --> D[ClassifierManager]
C --> E[FastText Model]
D --> G[EthicalClassifierModel]
G --> H[Conv1D]
H --> I[GlobalMaxPooling1D]
I --> J[Dense Layers]
A -->|"X_train, y_train"| B
B -->|"embed_texts(X)"| C
C -->|"tokenize(text)"| E
E -->|"word vectors"| G
G -->|"embeddings"| H
Ethical Manifolds are a multi-dimensional ethical space where texts can be positioned based on their ethical characteristics. This is achieved using a combination of sentence embedding models and classifiers trained on ethical dimensions such as:
- Fairness
- Utilitarianism
- Deontology
- Virtue ethics
- Care ethics
- Utilizes pre-trained FastText embeddings for robust word representation
- Implements a CNN-based classifier for each ethical dimension
- Supports multiple ethical dimensions (e.g., fairness, utility, virtue)
- Provides visualization tools for embedding analysis and ethical scores
- Sentence Embedding: Input text is converted into a high-dimensional vector using a pre-trained sentence embedding model.
- Ethical Classification: The embedding is passed through multiple classifiers, each trained on a specific ethical dimension.
- Manifold Positioning: The resulting scores are used to position the text within the ethical manifold.
- Visualization (optional): The high-dimensional ethical space can be reduced to 2D or 3D for visualization purposes.
To install Ethical Manifolds, follow these steps:
-
Clone the repository:
git clone https://github.com/crbazevedo/ethical-manifolds.git cd ethical-manifolds
-
Create a virtual environment (optional but recommended):
python -m venv env source env/bin/activate # On Windows, use `env\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
Here's a basic example of how to use Ethical Manifolds:
from ethical_manifolds import EthicalManifold
#Initialize the Ethical Manifold
manifold = EthicalManifold()
#Analyze a text
text = "AI should be developed with careful consideration of its ethical implications."
results = manifold.analyze(text)
#Print the results
for dimension, score in results.items():
print(f"{dimension}: {score}")
#Visualize the text in the ethical space (if visualization is enabled)
manifold.visualize(text)
For more detailed usage instructions and advanced features, please refer to the documentation.
The project currently supports the following ethical dimensions:
- Fairness Score
- Utility Score
- Virtue Score
The EthicalClassifierModel
uses a Convolutional Neural Network (CNN) architecture:
- Input layer accepting FastText word embeddings
- Convolutional layer (Conv1D)
- Global Max Pooling layer
- Dense layers for classification
We welcome contributions to the Ethical Manifolds project! If you'd like to contribute, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and commit them with clear, descriptive messages
- Push your changes to your fork
- Create a pull request to the main repository
Please read our Contributing Guidelines for more details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use Ethical Manifolds in your research or project, please cite it as follows:
@software{ethical_manifolds,
author = {Carlos R. B. Azevedo},
title = {Ethical Manifolds},
year = {2024},
url = {https://github.com/crbazevedo/ethical-manifolds}
}
For questions, suggestions, or collaborations, please open an issue on this repository or contact renatoaz@gmail.com.