agentsclimarketplace

Pytorch character level text to tensor conversion

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/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.From its SKILL.md

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

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.0 KB, 322 tokens by cl100k_base, as published. Nobody here has run it

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

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.