πŸ“–πŸ–‹οΈ C-Caption Transformer

Trained weights for a character-level, decoder-only transformer, built and trained from scratch, that writes short C programs from English captions, plans its steps, explains code and answers questions about C. The code, the training notebook, the dataset generator and a Streamlit app are on GitHub: laurelthejas/c-caption-transformer.

Model Decoder-only transformer: 6 layers, 6 attention heads, 384 channels, 1,024-character context
Parameters 11.1M
Vocabulary 92 characters
Training 8,000 steps on a Colab T4 GPU; best validation loss 0.054
Data 10,000 generated C programs from 36 task families, each with a plan and an explanation, plus 876 Q&A documents on 73 C topics

c_caption_transformer.safetensors holds the weights; config.json holds the model settings, the vocabulary and the training details; SHA256SUMS.txt holds checksums of both.

✍️ What it does

It continues one text format, ending each answer with // END:

/* Caption: Write a program to add 2 numbers. */   <- caption -> plan + code + explanation
/* Question: What does malloc do? */               <- question -> answer
Test Result
Familiar task ("Write a program to add 2 numbers.") βœ… Correct plan, code and explanation
New wording of a familiar task ("…uppercase a string") βœ… Correct
Familiar task with a twist ("Reverse the digits … and check whether it is the same number.") ⚠️ Only the familiar half
New task ("Armstrong number", "ASCII value of a") ❌ Writes the nearest familiar program

πŸš€ Use

The weights need c_caption_model.py from the GitHub repository, plus torch and safetensors. Keep config.json in the same folder as the weights.

from c_caption_model import CCaptionModel

model = CCaptionModel("c_caption_transformer.safetensors", "cpu")       # or "cuda"
print(model.write_program("Write a program to add 2 numbers."))
print(model.ask("What does malloc do?"))

The GitHub repository's app adds a gcc check that retries until a program compiles.

⚠️ Limitations

  • The model learned from 10,000 programs built from 36 task templates. For a request outside those patterns, it writes the closest program it has seen, so read what it produces.
  • "Compiles" does not mean "correct": numbers can disagree between the plan, the code and the explanation, and answers outside the 73 Q&A topics can be confidently wrong.
  • It shows how a transformer learns to plan, write and explain code from scratch on one free GPU, rather than serving as a general-purpose coding assistant, which would start from a large pretrained model.

βš–οΈ License

MIT, like the code. The training data is generated by make_c_dataset.py in the GitHub repository; it contains no third-party files.

Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support