AI Resume Analyzer Python, NLP

👤 Sharing: AI
```python
import re
import nltk
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

# Download required NLTK resources (run this once)
try:
    nltk.data.find('corpora/wordnet')
except LookupError:
    nltk.download('wordnet')
try:
    nltk.data.find('corpora/stopwords')
except LookupError:
    nltk.download('stopwords')
try:
    nltk.data.find('tokenizers/punkt')
except LookupError:
    nltk.download('punkt')

def preprocess_text(text):
    """
    Preprocesses the input text:
    1. Lowercases the text.
    2. Removes special characters and punctuation.
    3. Tokenizes the text.
    4. Removes stop words.
    5. Lemmatizes the tokens.
    """

    text = text.lower()
    text = re.sub(r'[^a-zA-Z\s]', '', text)  # Remove non-alphabetic characters

    tokens = nltk.word_tokenize(text)

    stop_words = set(stopwords.words('english'))
    tokens = [token for token in tokens if token not in stop_words]

    lemmatizer = WordNetLemmatizer()
    tokens = [lemmatizer.lemmatize(token) for token in tokens]

    return " ".join(tokens)


def analyze_resume(resume_text, job_description_text):
    """
    Analyzes the resume against the job description.

    Args:
        resume_text (str): The text content of the resume.
        job_description_text (str): The text content of the job description.

    Returns:
        float: The similarity score between the resume and the job description.
    """

    processed_resume = preprocess_text(resume_text)
    processed_job_description = preprocess_text(job_description_text)

    vectorizer = TfidfVectorizer()
    vectors = vectorizer.fit_transform([processed_resume, processed_job_description])

    similarity_score = cosine_similarity(vectors[0], vectors[1])[0][0]

    return similarity_score


def extract_skills(resume_text, skills_list):
    """
    Extracts skills from the resume based on a predefined skills list.

    Args:
        resume_text (str): The text content of the resume.
        skills_list (list): A list of skills to search for.

    Returns:
        list: A list of skills found in the resume.
    """
    found_skills = []
    resume_text = resume_text.lower()  # Case-insensitive matching

    for skill in skills_list:
        skill = skill.lower() # Case-insensitive matching
        if skill in resume_text:
            found_skills.append(skill)

    return found_skills


def main():
    """
    Main function to demonstrate the resume analyzer.
    """

    # Example usage:
    resume_text = """
    John Doe
    Software Engineer

    Summary:
    Highly motivated software engineer with 5+ years of experience in Python development,
    Natural Language Processing (NLP), and machine learning.  Proficient in using scikit-learn,
    TensorFlow, and PyTorch. Experienced in developing and deploying scalable applications.

    Skills:
    Python, NLP, Machine Learning, Deep Learning, TensorFlow, PyTorch, Scikit-learn, Java, Git, Docker

    Experience:
    Software Engineer, ABC Company (2018-Present)
    - Developed and maintained Python-based applications for NLP tasks.
    - Implemented machine learning models using scikit-learn and TensorFlow.
    - Deployed applications using Docker and Kubernetes.

    Education:
    Master of Science in Computer Science, XYZ University
    """

    job_description_text = """
    Software Engineer - Machine Learning

    We are looking for a software engineer with experience in machine learning and NLP.
    The ideal candidate should have strong Python skills and experience with TensorFlow and PyTorch.
    Experience with Docker and Kubernetes is a plus.

    Responsibilities:
    - Develop and deploy machine learning models.
    - Implement NLP algorithms.
    - Work with Python, TensorFlow, and PyTorch.
    """

    skills_list = ["Python", "NLP", "Machine Learning", "Deep Learning", "Java", "C++", "SQL", "Project Management", "Communication Skills", "TensorFlow", "PyTorch", "Docker", "Kubernetes", "Git"]


    similarity_score = analyze_resume(resume_text, job_description_text)
    print(f"Similarity Score: {similarity_score:.4f}")

    extracted_skills = extract_skills(resume_text, skills_list)
    print(f"Extracted Skills: {extracted_skills}")

if __name__ == "__main__":
    main()
```
👁️ Viewed: 21

Comments