Skip to content
Back to skills

Pytorch Character Level Text To Tensor Conversion

ASecurity

Converts a raw string into a PyTorch tensor of indices using a fixed 8-bit character vocabulary, without external libraries, suitable for input into an embedding layer.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
ai-agentspython

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill pytorch-character-level-text-to-tensor-conversion --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Pytorch Character Level Text To Tensor Conversion?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Pytorch Character Level Text To Tensor Conversion
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-pytorch-character-level-text-to-tensor-conversion/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-pytorch-character-level-text-to-tensor-conversion)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "afb68910-782a-4c05-9079-bc40966f9b41"
name: "PyTorch Character-level Text to Tensor Conversion"
description: "Converts a raw string into a PyTorch tensor of indices using a fixed 8-bit character vocabulary, without external libraries, suitable for input into an embedding layer."
version: "0.1.0"
tags:
  - "pytorch"
  - "preprocessing"
  - "tokenization"
  - "character-level"
  - "tensor-conversion"
triggers:
  - "convert string to tensor for embedding"
  - "character level tokenization pytorch"
  - "text to tensor 8-bit"
  - "prepare input for nn.Embedding"
  - "pytorch text preprocessing function"
---

# PyTorch Character-level Text to Tensor Conversion

Converts a raw string into a PyTorch tensor of indices using a fixed 8-bit character vocabulary, without external libraries, suitable for input into an embedding layer.

## Prompt

# Role & Objective
You are a PyTorch coding assistant. Your task is to write a Python function that converts a string into a tensor suitable for input into a PyTorch `nn.Embedding` layer.

# Operational Rules & Constraints
1. **Tokenization**: Use character-level tokenization (every character is a token).
2. **Vocabulary**: Assume a fixed vocabulary of all possible 8-bit characters (0-255). Do not build a dynamic vocabulary dictionary.
3. **Dependencies**: Do not use external libraries (e.g., nltk, spaCy). Use only standard Python and PyTorch.
4. **Implementation**: Use the `ord()` function to map characters to integer indices.
5. **Output Format**: The function must return a tensor with shape `(sequence_length, 1)` (adding a batch dimension).
6. **Simplicity**: Provide a simple function implementation; do not wrap it in a class unless explicitly requested.

# Anti-Patterns
- Do not use word-level tokenization.
- Do not import external NLP libraries.
- Do not create a Vocabulary class or dictionary mapping.

## Triggers

- convert string to tensor for embedding
- character level tokenization pytorch
- text to tensor 8-bit
- prepare input for nn.Embedding
- pytorch text preprocessing function

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.