Skip to content

munjed-ab/code2art

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Code2art Generator

sample_final_version

This project explores an unusual idea: transforming code features into art. It’s an ongoing experiment in using neural networks to visualize the structure and “feel” of code as images — not for aesthetics alone, but to find patterns and relationships hidden inside code representations.

I’m building and refining this project gradually, learning as I go. It’s not perfect, and that’s exactly why it’s here — to grow.


Overview

The model takes a numerical feature representation of code and generates images that reflect underlying structure and semantics. The generator is trained to preserve variance, similarity, and diversity across features, and then evaluated using several clustering and correlation metrics.

samples_256_20251017_1130_final

The included evaluator (CodeImageEvaluator) measures:

  • Clustering Quality: how well the generated images group by code type
  • Similarity Preservation: how code similarity translates into image similarity
  • Diversity: visual and statistical diversity of outputs
  • t-SNE Visualization: 2D projection of generated images for visual inspection

Example visualization: tsne_visualization (1)


Try It on Hugging Face

You can try the model interactively on Hugging Face Spaces.

A simple demo lets you:

  • Input your own code
  • Watch it generate an image instantly
  • Explore how feature changes affect the final output

Live Demo: https://huggingface.co/spaces/munjed/code2art


Current Results

Silhouette Score: 0.2800
Calinski-Harabasz: 1526.63
Davies-Bouldin: 1.52

Pearson Correlation: 0.92
Spearman Correlation: 0.80

Within-image Variance: 0.40
Between-image Diversity: 361.50

The model currently shows strong similarity preservation, meaning it captures relationships between code samples well, but clustering and visual clarity still need work.


Current Problems

  • Generated images lack strong structural coherence — they sometimes look abstract or noisy.
  • Loss stability issues — balancing variance and reconstruction terms is tricky.
  • Feature variance preservation can explode or vanish depending on learning rate and scaling.
  • Higher resolutions (e.g. 256x256) increase complexity fast, sometimes degrading output quality.
  • Code Extraction need more improvement to get the features dataset we need for different languages.

Next Steps

  • Stabilize training using better loss normalization and dynamic weighting.
  • Experiment with pretrained visual priors or diffusion-based conditioning.
  • Possibly integrate contrastive learning or VAE-like embeddings.

License

MIT — feel free to use, modify, and build upon it.

final_samples (7)

test

About

Generating Abstract Visual Representations from Source Code Using Neural Networks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published